ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. How to Create a Unique ID in Excel With a Formula

How to Create a Unique ID in Excel With a Formula

By ExcelReady Team·Updated November 3, 2026·6 min read

The short answer

To create a unique ID in Excel, join a text prefix to a padded number: ="EMP-"&TEXT(ROW()-1,"0000") gives EMP-0001, EMP-0002 and so on. For IDs per category, count earlier matches: =UPPER(LEFT(B2,3))&"-"&TEXT(COUNTIF($B$2:B2,B2),"000"). Then paste the IDs as values so they never change, and check for repeats with COUNTIF.

Key takeaways

  • Most IDs are a prefix plus a padded number, joined with & and TEXT(number,"0000").
  • COUNTIF with a growing range, $B$2:B2, numbers each category separately: SAL-001, SAL-002.
  • ROW-based IDs change when you sort or delete rows. Paste IDs as values once they are assigned.
  • Check that every ID is unique with =COUNTIF($A$2:$A$100,A2)>1 or a duplicate highlight.
On this page+
  1. What makes a good unique ID?
  2. How to create a simple ID with a prefix and number
  3. How to create IDs by category
  4. How to create date-based IDs
  5. How to keep leading zeros in IDs
  6. How to stop IDs from changing
  7. How to check that every ID is unique
  8. Practise it

To create a unique ID in Excel, you join a short text prefix to a number that never repeats, such as EMP-0001 or SAL-003. Excel has no "make an ID" button, but a one-line formula with &, TEXT and sometimes LEFT or COUNTIF does the job. This guide shows the common ID styles, how to keep them from changing, and how to prove that no ID appears twice.

What makes a good unique ID?#

A good ID is unique, never changes once assigned, and is easy to read and type. In practice that means:

  • A short prefix that says what the record is, such as EMP, INV or SAL.
  • A padded number, such as 0001, so IDs sort correctly and have the same length.
  • No meaning that might change. An ID built from a surname breaks when the person changes their name.

Here are the formulas in this guide:

ID styleExampleFormula
Prefix + row numberEMP-0001="EMP-"&TEXT(ROW()-1,"0000")
Prefix + department countSAL-003=UPPER(LEFT(B2,3))&"-"&TEXT(COUNTIF($B$2:B2,B2),"000")
Date + daily countINV-250314-02="INV-"&TEXT(C2,"yymmdd")&"-"&TEXT(COUNTIF($C$2:C2,C2),"00")
Number with display formatEMP-0001Custom format "EMP-"0000 on 1, 2, 3

How to create a simple ID with a prefix and number#

Join the prefix and a padded number. With headers in row 1, the first record is in row 2, so ROW()-1 gives 1, 2, 3 down the list:

Excel formula
="EMP-"&TEXT(ROW()-1,"0000")
  • ROW() returns the current row number.
  • TEXT(...,"0000") pads it to four digits, so 1 becomes 0001.
  • & joins the prefix and the number into EMP-0001.

Fill it down (Windows: Ctrl+D; Mac: ⌘D) for EMP-0002, EMP-0003 and so on. The TEXT function guide and the list of TEXT format codes explain "0000". Other ways to number rows, including SEQUENCE, are in how to auto number rows.

To make a whole block of IDs at once in Microsoft 365 or Excel 2021, combine TEXT with SEQUENCE:

Excel formula
="EMP-"&TEXT(SEQUENCE(50),"0000")

This spills EMP-0001 to EMP-0050 into the 50 cells below. Because one formula produces every ID, paste the results as values once they are assigned, so they no longer depend on it.

You can also type EMP-0001 in the first cell and drag the fill handle down. Excel usually continues the number at the end of the text, and the result is fixed text from the start.

How to create IDs by category#

To number each department separately, count how many times the department has appeared so far. In C2:

Excel formula
=UPPER(LEFT(B2,3))&"-"&TEXT(COUNTIF($B$2:B2,B2),"000")

Fill it down. With this data, the IDs are:

ABC
1EmployeeDeptID
2MayaSalesSAL-001
3TomasFinanceFIN-001
4AishaSalesSAL-002
5JunHRHR-001
6LeoSalesSAL-003

How it works:

  • LEFT(B2,3) takes the first three letters of the department. The LEFT function guide shows more examples. "HR" has only two letters, so LEFT returns HR.
  • UPPER makes the prefix capitals.
  • COUNTIF($B$2:B2,B2) counts matches from row 2 down to the current row. The first part is locked with $, and the second part grows as you fill down. In row 6 the range is B2:B6, which holds three Sales rows, so the count is 3.

Watch for departments that share the first three letters, such as "Marketing" and "Marine". Use a lookup table of fixed codes instead if that happens.

How to create date-based IDs#

Invoices and tickets often include the date. With the date in C2:

Excel formula
="INV-"&TEXT(C2,"yymmdd")&"-"&TEXT(COUNTIF($C$2:C2,C2),"00")

For the second invoice on 14 March 2025, this returns INV-250314-02. TEXT(C2,"yymmdd") turns the date into 250314, and the COUNTIF numbers invoices within the same day. The yymmdd order keeps IDs in date order when sorted as text.

How to keep leading zeros in IDs#

Leading zeros disappear when an ID is stored as a number: 0007 becomes 7. You have two options:

  • Formula IDs: TEXT returns text, so TEXT(7,"0000") keeps 0007.
  • Number IDs: keep the value 7 and apply a custom number format such as "EMP-"0000. The cell shows EMP-0007, but lookups must use the number 7.

The guide to leading zeros in Excel covers both, plus importing data without losing them.

How to stop IDs from changing#

An ID must stay with its record forever. Formula IDs can break this rule:

  • ROW() changes when you sort the list or delete a row above.
  • COUNTIF($B$2:B2,B2) changes if you sort, or insert a record in the middle.

So once IDs are assigned, freeze them. Select the ID column, copy it, and use Paste Special > Values (Windows: Ctrl+Alt+V, then V; Mac: ⌃⌘V). For new records, add them at the bottom and copy the formula down to the new rows only, then paste those as values too.

In an Excel table (Ctrl+T; Mac: ⌘T), a formula column fills itself for new rows, which is handy. Remember to paste the new IDs as values after adding records.

How to check that every ID is unique#

Never assume IDs are unique; check. Next to the first ID, type:

Excel formula
=COUNTIF($C$2:$C$100,C2)>1

Fill it down. TRUE means the ID appears more than once. For a single answer, =SUMPRODUCT(--(COUNTIF(C2:C6,C2:C6)>1)) counts the duplicate rows; 0 means all is well.

You can also highlight repeats with Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values. For IDs built from names, such as emails, duplicates are common, so the check matters even more; see how to create an email address from a name. More joining techniques are in how to combine text in Excel.

Practise it#

Every ID formula in this guide is joined text plus a formatted number. Practise joining text with &, CONCAT and TEXTJOIN, then practise TEXT and VALUE to control zeros and formats: you type each formula and it checks it instantly. Or build the department IDs in the exercise on this page first.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Give each employee an ID made of the first three letters of their department and a running number for that department. In C6, type =UPPER(LEFT(B6,3))&"-"&TEXT(COUNTIF($B$2:B6,B6),"000") and press Enter.

fx
ABCD
1
Employee
Dept
ID
2
Maya
Sales
3
Tomas
Finance
4
Aisha
Sales
5
Jun
HR
6
Leo
Sales
7
8
9

Tip: LEFT takes SAL from Sales. COUNTIF($B$2:B6,B6) counts how many Sales rows there are up to this row (3), and TEXT pads it to 003.

Practise this in a lesson

LessonJoining text: &, CONCAT and TEXTJOINBuild full names, addresses and tag lists by joining text with &, CONCAT and TEXTJOIN.LessonTEXT and VALUE: numbers to text and backFormat dates and dollar amounts inside sentences with TEXT, and turn digits stored as text into real numbers with VALUE.Function guideTEXTFormat dates, prices and percentages inside labels with Excel's TEXT function. Format codes, common mistakes and a live practice exercise.Function guideLEFTPull the first characters from a cell with Excel's LEFT: prefixes, initials and first names. Examples, pitfalls and live practice.

Frequently asked questions

How do I generate a unique ID in Excel automatically?

+

Use a formula such as ="ID-"&TEXT(ROW()-1,"0000") and fill it down, or put it in an Excel table so new rows get it automatically. Paste the results as values once assigned, so sorting or deleting rows can't change them.

How do I create an ID with letters and numbers in Excel?

+

Join text and a formatted number with &. For example, =UPPER(LEFT(B2,3))&"-"&TEXT(A2,"000") takes the first three letters of B2, adds a dash and pads the number in A2 to three digits.

How do I keep leading zeros in an ID like 0007?

+

Use TEXT(number,"0000") inside the formula, which returns text with the zeros kept. For plain numbers, a custom number format of 0000 shows the zeros without changing the value.

Is there a GUID or UUID function in Excel?

+

There is no built-in worksheet function for GUIDs. For most lists, a prefix plus a sequential number is easier to read and check. If you need system-generated IDs, create them in the source system or with a macro.

How do I check that IDs are unique?

+

Next to each ID, type =COUNTIF($A$2:$A$100,A2)>1. TRUE means the ID appears more than once. You can also use Home > Conditional Formatting > Highlight Cells Rules > Duplicate Values.

Sources

  • TEXT function - Microsoft Support
  • LEFT, LEFTB functions - Microsoft Support
  • COUNTIF function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. What makes a good unique ID?
  2. How to create a simple ID with a prefix and number
  3. How to create IDs by category
  4. How to create date-based IDs
  5. How to keep leading zeros in IDs
  6. How to stop IDs from changing
  7. How to check that every ID is unique
  8. Practise it

Keep reading

Text· 5 min read

How to Add or Keep Leading Zeros in Excel

To add leading zeros in Excel, use =TEXT(A2,"00000"), which pads a number to five digits, so 742 becomes 00742. To keep the cell a number, apply a custom number format of 00000 instead. To type an ID with zeros and keep them, format the cells as Text first or start the entry with an apostrophe, like '00742.

Text· 7 min read

How to Combine Text in Excel (&, CONCAT, TEXTJOIN)

To combine text in Excel, join the pieces with &: =A2&" "&B2 turns Nora and Delgado into Nora Delgado. CONCAT does the same with a list of pieces. TEXTJOIN puts the same separator between every piece and can skip empty cells: =TEXTJOIN(", ",TRUE,C2:E2). Type spaces and commas yourself, inside double quotes.

Dynamic arrays· 5 min read

Auto Number Rows in Excel (SEQUENCE and ROW)

To auto number rows in Excel, type =ROW()-1 in A2 and fill it down: each row shows its own number and renumbers itself when rows are deleted. In Excel 2021 or Microsoft 365, =SEQUENCE(COUNTA(B2:B100)) numbers every filled row with one formula that grows as you add data. For fixed numbers, use the fill handle.

More on text

  • Get Initials From a Name in Excel
  • LEFT, RIGHT and MID in Excel: Pull Out Part of a Cell
  • Line Breaks in Excel: In a Cell and in a Formula
  • MID Function in Excel: Pull Text From the Middle
  • How to Convert a Number to Words in Excel
  • Excel REGEX Functions: REGEXTEST, REGEXEXTRACT, REGEXREPLACE
All text articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free