Concatenating cells with differing leading zeros

broncos347

Active Member
Joined
Feb 16, 2005
Messages
291
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet where i have four columns (B, D, E &F) which hold info which i need to concatenate to create a unique reference number.

The issue i have is that the first column contains text, the second & third contain two digits and the fourth contains three. The second, third & fourth columns all contain leading zeros and when i concatenate them the zero's disappear.

i've search the forum and whilst i can find ways to retain the zeros but the formulas are based on cells with the same number of digits.

any help would be greatly appreciated.
 

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.
Use the TEXT function to maintain the zeroes, i.e.
Code:
=B2 & TEXT(C2,"00") & TEXT(D2,"00") & TEXT(E2,"000")
 
Upvote 0
Joe4, brilliant many thanks. If i wanted to put a space or a hash inbetween each cell what would be the best way?
 
Upvote 0
Just add it in. Remember, concatenate just combines a bunch of strings/values.
So, it would just look something like (dashes):
Code:
=B2 & "-" & TEXT(C2,"00") & "-" & TEXT(D2,"00") & "-" & TEXT(E2,"000")
or this (spaces):
Code:
=B2 & " " & TEXT(C2,"00") & " " & TEXT(D2,"00") & " " & TEXT(E2,"000")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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