ExcelVBA-In a column, change only cells that

[Closed]
Report
-
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
-
Hello,

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?

Thanks

1 reply

Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
803
suppose the data
0
1
0
7
2
0
31
10
0
1
in from A2 down. A1 is having column heading.

in B2 copy paste this formula
=IF(LEN(A2)=1,0&A2,A2)
copy B2 down.