How can I generate GUIDs in Excel?

前端 未结 11 1038
别那么骄傲
别那么骄傲 2020-11-27 14:58

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 Exce

11条回答
  •  旧时难觅i
    2020-11-27 15:53

    I created a VBA function that works both on mac and windows:

    https://github.com/Martin-Carlsson/Business-Intelligence-Goodies/blob/master/Excel/GenerateGiud/GenerateGiud.bas

    'Generates a guid, works on both mac and windows 
    Function Guid() As String
        Guid = RandomHex(3) + "-" + _
            RandomHex(2) + "-" + _
            RandomHex(2) + "-" + _
            RandomHex(2) + "-" + _
            RandomHex(6)
    End Function
    
    'From: https://www.mrexcel.com/forum/excel-questions/301472-need-help-generate-hexadecimal-codes-randomly.html#post1479527
    Private Function RandomHex(lngCharLength As Long)
        Dim i As Long
        Randomize
        For i = 1 To lngCharLength
            RandomHex = RandomHex & Right$("0" & Hex(Rnd() * 256), 2)
        Next
    End Function
    

提交回复
热议问题