Excel Concatenate with Leading Zeros: A How-To Guide
In this article
To concatenate values in Excel while keeping leading zeros, you must first format the source cells as Text or use the TEXT function to preserve the zeros, then join them with the & operator or CONCATENATE. For example, =TEXT(A1,"00000")&B1 keeps a five-digit code like 00123 intact. If you simply use =A1&B1 on a number stored as 123, Excel drops the zeros and you get 123B1. The fix is always to control the number format before or during the join.
What You'll Need
- Microsoft Excel (any recent version for Windows, Mac, or the web). The steps below use the desktop ribbon; labels can differ slightly by version and region.
- Your data in a worksheet, with the column containing leading-zero values identified.
- Basic familiarity with formulas and the Formula Bar.
Step-by-Step
- Decide whether the zeros are formatting or data. If you typed
00123into a cell and Excel shows123, the zeros were never stored—they were only display formatting. If the cell was imported as text, the zeros are part of the value. This distinction determines which method you use. - For values that must keep zeros, format the source column as Text before entering data. Select the column, right-click, choose Format Cells, pick Text, and click OK. Then re-enter or re-import the values. Text-formatted cells display exactly what you type, including leading zeros.
- If the data is already numeric and you cannot change it, use the TEXT function in your concatenation formula. The syntax is
=TEXT(value, "format"). For a five-digit code, use"00000". For a code with a prefix, use something like"00-000". Example:=TEXT(A2,"00000")&"-"&B2produces00123-ABC. - Use the ampersand (&) operator to join cells. In a new column, type
=, click the first cell, type&, click the second cell, and press Enter. For example,=A2&B2. If you need a separator, put it in quotes:=A2&"-"&B2. - Alternatively, use the CONCATENATE function (or CONCAT in newer versions).
=CONCATENATE(A2,B2)or=CONCAT(A2,B2). The behavior is the same; CONCATENATE is older and still works, while CONCAT is the modern replacement. - Combine TEXT with concatenation when the source is numeric. Replace the plain cell reference with
TEXT(cell,"00000"). For example,=TEXT(A2,"00000")&B2. This forces Excel to treat the number as a zero-padded string during the join. - Copy the formula down the column. Drag the fill handle or double-click it to apply the formula to all rows. Verify a few results to ensure zeros are preserved.
- Convert the formula results to values if you need to remove the formulas. Select the concatenated column, copy it, then use Paste Special > Values. This replaces formulas with static text, which is useful before exporting or sharing.
- Check for hidden spaces or non-printing characters. If results look wrong, use
TRIMorCLEANon the source cells before concatenating:=TEXT(TRIM(A2),"00000")&B2.
Common Mistakes
- Assuming zeros are stored when they are only formatted. A cell showing
00123may actually contain the number 123. Concatenation will drop the zeros. Always check the Formula Bar; if it shows 123, the zeros are not there. - Using the wrong number of zeros in the TEXT format. The format string
"000"pads to three digits;"00000"pads to five. If your codes vary in length, you may need a dynamic approach or a fixed width that matches your longest code. - Forgetting to format the result column as Text. If the concatenated result itself starts with zeros and you later re-enter it as a number, the zeros will vanish again. Keep the result as text or paste as values into a text-formatted column.
- Mixing text and numbers without conversion. Concatenating a text cell with a numeric cell can produce unexpected results if the numeric cell has its own formatting. Use TEXT on the numeric cell to control its appearance.
- Using CONCATENATE with a range instead of individual cells. CONCATENATE does not accept ranges like A2:A10; it requires individual arguments. Use CONCAT or TEXTJOIN for ranges.
Tips
- Use
TEXTJOIN(Excel 2019 and later, Microsoft 365) to concatenate a range with a delimiter while preserving formatting:=TEXTJOIN("-",TRUE,TEXT(A2,"00000"),B2). - If you frequently import data with leading zeros, set the import column type to Text in Power Query or the Text Import Wizard to avoid losing zeros at the source.
- For codes that must always be a fixed length, consider using a custom number format like
00000on the source cell. This displays zeros without changing the underlying number, but remember that concatenation uses the underlying value, so you still need TEXT in the formula. - Test your formula on a few rows before filling down. A single mistake in the format string can affect every row.
- When sharing the workbook, paste formulas as values to prevent recalculation issues or accidental changes to the source data.
Troubleshooting
If your concatenated result still drops leading zeros, check the source cell's actual value in the Formula Bar. If it is numeric, the zeros are not stored; you must use TEXT or reformat and re-enter the data. If the source is text but the result loses zeros, ensure the result cell is formatted as Text or that you are not performing any mathematical operation on it. If you see #VALUE! errors, verify that all arguments in TEXT are valid and that you have not mixed text and numbers incorrectly. If the formula works for some rows but not others, look for inconsistent data types or hidden characters; use ISTEXT or ISNUMBER to diagnose. Finally, if you are using an older version of Excel, confirm that functions like TEXTJOIN are available; otherwise, use CONCATENATE with individual TEXT calls.
Frequently Asked Questions
Why does Excel remove leading zeros when I concatenate?
Because Excel treats the value as a number, and numbers do not store leading zeros. Concatenation converts the number to text using its general format, which omits leading zeros. Use the TEXT function to specify the desired format.
Can I keep leading zeros without using TEXT?
Yes, if you format the source cells as Text before entering the data. Then concatenation will preserve the zeros because the value is stored as a text string. However, you cannot perform mathematical operations on those cells without converting them back to numbers.
What is the difference between CONCATENATE and CONCAT?
CONCATENATE is the older function and does not accept ranges. CONCAT is the newer function that can accept ranges and is available in Excel 2019 and later. Both join text strings; for leading zeros, both require TEXT or text-formatted sources.
How do I concatenate a whole column with leading zeros?
Use a formula like =TEXT(A2,"00000")&B2 in the first row and fill down. If you need to join multiple cells across a row, use & or CONCAT with TEXT for each numeric cell. For ranges, use TEXTJOIN with an array of TEXT functions, but note that TEXTJOIN may require dynamic arrays or Ctrl+Shift+Enter in older versions.
Can I use a custom number format instead of TEXT?
Custom number formats change only the display, not the underlying value. Concatenation uses the underlying value, so a custom format alone will not preserve leading zeros in the result. You must use TEXT or store the data as text.
What if my leading zeros are in a date or time?
Dates and times are stored as numbers, so concatenation will convert them to serial numbers unless you use TEXT with a date format, e.g., TEXT(A2,"mm/dd/yyyy"). Apply the same principle: use TEXT to control the output string.