Skip to content

Instantly share code, notes, and snippets.

Created July 14, 2015 12:37
Show Gist options
  • Save msubel/9c70951a20efe5c72195 to your computer and use it in GitHub Desktop.
Save msubel/9c70951a20efe5c72195 to your computer and use it in GitHub Desktop.
An Excel Fromula to generate a UUID v4
Copy link

pownas commented Apr 13, 2023

Svenska/Swedish one-liner:


Indented for readability:


Other languages translated on this page:

Copy link

pbubar commented Nov 28, 2023

I get #NUM! errors one in every few thousand calculations of this formula.

Here is why:

  • POWER(16;4) returns 65536.
  • RANDBETWEEN is inclusive of the 'bottom' and 'top' values.
  • DEC2HEX(65536;4) throws the NUM error as its needs 5 characters; the highest value DEC2HEX can return in 4 characters is 65535
  • So the POWER() function is giving a 'top' bound to the RANDBETWEEN that is exactly 1 too high.

The fix is to add -1 after each use of the POWER() function in the formula:


Copy link

JesseWStratton commented Mar 15, 2024

Just one question... The GUID's get refreshed evertime I do something to the column or near the column that contain the formula. Is there a way to just generate it once and fix the generated GUID's?

Regards, Arie

I set one cell in excel to be my UUID generator using the formula and naming the range, then I use VBA to refer to the named range when I want to commit the value to a stored location using something like:

For Each rRecord In rNewRecords
     rRecord.Offset(0, -1).Value = [r_uuid].Value
Next rRecord

Where r_uuid is a named range in the workbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment