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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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