Excel VBA – In a column, change only cells that

February 2017



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


Published by aakai1056. Latest update on January 21, 2010 at 03:13 PM by aakai1056.
This document, titled "Excel VBA – In a column, change only cells that," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).