FormulaCraft

How to generate a unique ID in Excel and Google Sheets

Excel & Google Sheets
=TEXT(ROW()-1,"0000")

Verified example

Computed by a real spreadsheet engine on the sample data below.

IDName
Alice
Bob
Carol

=TEXT(ROW()-1,"0000")0000

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1For sequential IDs, use =TEXT(ROW()-1,"0000") in row 2 to get 0001, 0002, 0003 as you copy it down.
  2. 2For prefixed IDs, concatenate a label: ="INV-"&TEXT(ROW()-1,"0000") produces INV-0001, INV-0002.
  3. 3For date-stamped IDs, use ="ID-"&TEXT(TODAY(),"YYYYMMDD")&"-"&TEXT(ROW()-1,"000") to include today's date.
  4. 4For random IDs that look like GUIDs, combine multiple RANDBETWEEN calls: ="ID-"&RANDBETWEEN(1000,9999)&"-"&RANDBETWEEN(1000,9999) — note these recalculate on edit, so paste as values to freeze them.

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Does Google Sheets have a UUID or GUID function?

No built-in one, but you can use a combination of RANDBETWEEN calls or a Google Apps Script function: =generateUUID() if you add the script.

How do I make IDs that don't change when rows are inserted?

Use ROW()-based IDs only if your table is stable. For robust IDs, generate them once with RANDBETWEEN and paste as values, or store them in a column that you manually populate.

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: