Need a formula that will force a number string to set length and left pad with zeroes

rjhillcbytwp

New Member
Joined
Dec 16, 2008
Messages
13
All,
Excel does a lovely job of providing tools to remove leading zeroes, spaces ect. from a string. What I need to do is force a string to a certain length (7 chars), and left pad with zeroes if it is short. I'd like to do this in a formula that I can "drag copy" down the sheet to apply to all rows in a book.

Example: cell contains 1234567 - copy as is to new cell
cell contains 123456 - write 0123456 to new cell
12345 - write 0012345 to new cell
1234 - write 0001234 to new cell
123 - write 0000123 to new cell
I'm simply out of ideas. The reason for the exercise is that I'm doing a vlookup against two sheets, the first sheet is a dump from a database of an unknown type where the cell contains a numeric id. The second is a locked-down, hand-crafted sheet with the comparison ID residing in a text cell. This is the correct sheet, and I cannot change or edit this data. I believe retooling the variable numeric values to a consistent, 7 character string is the way to get my vlookup to find matches.

Any help is always appreciated.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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