Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate GUIDs in Excel?

Tags:

guid

excel

vba

I have an excel file with one order on each row, and I want each order to have a unique identifier, so there will be a Unique ID column. Every time I fill a row, I want Excel to automatically populate the Unique ID column for me. I did some research and was pointed in the direction of GUIDs. I found the following code:

Function GenGuid() As String Dim TypeLib As Object Dim Guid As String Set TypeLib = CreateObject("Scriptlet.TypeLib") Guid = TypeLib.Guid ' format is {24DD18D4-C902-497F-A64B-28B2FA741661} Guid = Replace(Guid, "{", "") Guid = Replace(Guid, "}", "") Guid = Replace(Guid, "-", "") GenGuid = Guid End Function 

but I am not sure how I can implement it. Any help would be greatly appreciated. Thank you in advance.

like image 479
abw333 Avatar asked Aug 11 '11 19:08

abw333


People also ask

Can I generate GUID in Excel?

I used 'outside dragging option' in excel to generate guid in batch. Here is a kind of hacky and incomplete explanation, I found the function =randbetween(x,y) changes its value everytime we hit 'enter' anywhere with a new value.

How do you generate GUIDs?

To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.

What is GUID generator?

A GUID (globally unique identifier) is a 128-bit text string that represents an identification (ID). Organizations generate GUIDs when a unique reference number is needed to identify information on a computer or network. A GUID can be used to ID hardware, software, accounts, documents and other items.


2 Answers

The following Excel expression evaluates to a V4 GUID:

=CONCATENATE(DEC2HEX(RANDBETWEEN(0,4294967295),8),"-",DEC2HEX(RANDBETWEEN(0,65535),4),"-",DEC2HEX(RANDBETWEEN(16384,20479),4),"-",DEC2HEX(RANDBETWEEN(32768,49151),4),"-",DEC2HEX(RANDBETWEEN(0,65535),4),DEC2HEX(RANDBETWEEN(0,4294967295),8))

-or (depending on locale setting/decimal and list separators)-

=CONCATENATE(DEC2HEX(RANDBETWEEN(0;4294967295);8);"-";DEC2HEX(RANDBETWEEN(0;65535);4);"-";DEC2HEX(RANDBETWEEN(16384;20479);4);"-";DEC2HEX(RANDBETWEEN(32768;49151);4);"-";DEC2HEX(RANDBETWEEN(0;65535);4);DEC2HEX(RANDBETWEEN(0;4294967295);8))

Note that the first character of the third group is always 4 to signify a V4 (pseudo-random number generated) GUID/UUID per RFC 4122 section 4.4.

Also note that the first character of the fourth group is always between 8 and B per the same RFC.

Standard disclaimer: the resulting GUIDs/UUIDs are not cryptographically strong.

Edit: remove invisible characters

like image 164
NekojiruSou Avatar answered Sep 23 '22 21:09

NekojiruSou


I used the following function in v.2013 excel vba to create a GUID and is working well..

Public Function GetGUID() As String      GetGUID = Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36)  End Function  
like image 27
rchacko Avatar answered Sep 21 '22 21:09

rchacko