Excel VBA – In a column, change only cells that

Ask a question


Issue


In Excel VBA, In a column, I want to change only cells that has only one character and add a "0" (zero) prefix.

for example if column C contains the data below,

0 
1 
0 
7 
2 
0 
31 
10 
0 
1


I want to replace those with only one character and add a 0 prefix to look like

00 
01 
00 
07 
02 
00 
31 
10 
00 
01 


Can anyone please help how to code this in Excel VBA?

Solution


In Excel VBA, In a column, I want to change only cells that has only one character and add a "0" (zero) prefix.

for example if column C contains the data below,

0 
1 
0 
7 
2 
0 
31 
10 
0 
1 


I want to replace those with only one character and add a 0 prefix to look like

00 
01 
00 
07 
02 
00 
31 
10 
00 
01 

Can anyone please help how to code this in Excel VBA?

Note


Thanks to venkat1926 for this tip on the forum.

Excel Macro - Dynamic Column Selection
Excel - Copy data from one sheet to another