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

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

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

Related tasks

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

Last reviewed: