Adding a leading zero to numbers

siasarma

New Member
Joined
Sep 20, 2008
Messages
46
I have a list of a couple thousand customer numbers. Some of them are 5 digits long and some are 6. I was just told that we have to have them all the same number of digits long. So, I am going to add a leading zero to them. Example the number is 12345 I want to make it 012345. Does anyone know of an easy way to format all these to have a leading zero, so I don't have to go through a couple of thousand of these and type a zero in there??? Thanks!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Edit:

Try =IF(LEN(A1)=5,TEXT("0"&A1,"000000"),A1)
 
Upvote 0
Hi,

For this you would need to format the cells as text;

Right Click - Format - Number Format - Text

And then you will be able to add the first zero's back in.

You could use this code to put the zero's in for you;

Code:
Dim lRow As Long

lRow = Range("A" & Rows.count).End(xlUp).Row

For i = 2 To lRow
    If Len(Cells(i, 1)) = 5 Then
        Cells(i, 1) = "0" & Cells(i, 1).Value
    End If
Next i
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top