How do i cocantenate with leading zeros and a hyphen

touque

Board Regular
Joined
Jan 22, 2009
Messages
107
I have a large spreadsheet where I have one column with a 6 digit number and the next column with a single digit number. I wish to cocantenate them but need 2 zeros to the left of the 6 digit number and 1 zero to the left of the single digit number and a hyphen between the two like so.

Cell in column A 152470 and cell in column B 2 to end up with 00152470-02 in cell in column C.

I tried using two more columns where formatted those columns so as to read 00152470 and 02 but once I cocantenated the two in a third column I lost the left zeros to read 152470-2 not 00152470-02.

Does anyone have any suggestions?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
=text(a2, "00000000-") & text(b2, "00")

I assume the OP noticed that he needed to add an additional zero (shown in red above) in order to produce the 8-digit number he wanted in front of the dash.

Here is another formula that would also work...

=TEXT(100*A2+B2,"00000000-00")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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