Add leading zeros

j3andc

Board Regular
Joined
Mar 4, 2002
Messages
172
I am creating a file that will be used to upload data to a website. the information is very specific in format. Specifically the text string has to be a specific length. This is a problem when I have an amount, because the amount is variable and therefore the leading zeros change with each record. Is there a way to tell excel to add enough zeros to the front edge of the text string to make the new text string 10 characters?

Thanks for any help.

Jim
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If you wanted to zero pad cell A1 so that it is exactly 10 spaces:
Code:
=REPT("0",10-LEN(A1)) & A1
 
Upvote 0
=TEXT(insert reference cell,"0000000000")
Just be careful with that. That assumes that you just have numbers (entered as numbers), and no decimals.
So it wouldn't work for things like text entries (I often see numbers entered as text) or decimals.
 
Upvote 0
Code:
=TEXT(insert reference cell,"0000000000")
Joe4's formula limits the output to exactly 10 digits... if an 11-digit number is put into the referenced cell, his formula output alerts the user that there are too many digits to form the required 10-digit number. Your formula, on the other hand, would output the full 11 digits without warning (and that value could not be used in the way it is needed).
 
Upvote 0
Just be careful with that. That assumes that you just have numbers (entered as numbers), and no decimals.
So it wouldn't work for things like text entries (I often see numbers entered as text) or decimals.

Good point. Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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