Spreadsheet Practice

How to create an ID with a prefix and leading zeros in Excel

Formula (Excel and Google Sheets)

=$E$1&TEXT(A2,"00000")

Pad the number with TEXT and join the prefix: =$E$1&TEXT(A2,"00000") turns 42 into INV-00042.

Result on the example
one result per row in B2, filled down to B6
Works in
Every current version
Google Sheets
Same formula

See it work

The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.

How it works

Each 0 in the format "00000" is a digit that is always shown, so 42 becomes "00042". Joining the prefix in front gives IDs that are all the same length and sort correctly as text.

=$E$1&TEXT(A2,"00000")

Result"INV-00001"

  1. $E$1"INV-"

    The value in E1.

  2. A21

    The value in A2.

  3. TEXT(A2,"00000")"00001"

    TEXT: Formats a number or date as text, e.g. "mmm" or "$#,##0".

    • valueA21
    • format_text"00000"
  4. $E$1&TEXT(A2,"00000")"INV-00001"

    The & operator joins as text.

In Google Sheets

The same formula works in Google Sheets: =$E$1&TEXT(A2,"00000"). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=$E$1&RIGHT("00000"&A2,5)INV-00001, INV-00002, INV-00042…Pads by putting zeros in front and keeping the last 5 characters.
=$E$1&TEXT(ROW()-1,"00000")INV-00001, INV-00002, INV-00003…Different resultNumbers the rows by position instead of from a column. INV-00001 to INV-00005, one per row, whatever is in column A.

Common mistakes

  • Numbers with more digits than the format are not cut: 123456 gives "INV-123456", one digit longer than the rest.
  • IDs based on ROW() change when you sort or delete rows. Use them only to create IDs, then paste them as values.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Create an ID with a prefix and leading zeros

In B2, build the ID: the prefix in E1 followed by the number padded to 5 digits. Fill down to B6.

Questions

How do I generate a whole list of IDs at once?

In Excel 365: ="INV-"&TEXT(SEQUENCE(100),"00000") spills 100 IDs.

How do I get the next ID?

Pad the highest number plus one: =$E$1&TEXT(MAX(A2:A6)+1,"00000").

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.