Excel VBA – In a column, change only cells that

December 2016



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.

Related :

This document entitled « Excel VBA – In a column, change only cells that » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.