ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   My ultimate goal is to create an ID that will always be unique (https://www.excelbanter.com/excel-programming/361315-re-my-ultimate-goal-create-id-will-always-unique.html)

RB Smissaert

My ultimate goal is to create an ID that will always be unique
 
One way of making unique ID numbers:

Private Declare Function CoCreateGuid Lib "ole32" (id As Any) As Long

Function CreateGUID() As String

Dim btID(0 To 15) As Byte
Dim i As Long

If CoCreateGuid(btID(0)) = 0 Then
For i = 0 To 15
CreateGUID = CreateGUID + IIf(btID(i) < 16, "0", "") +
Hex$(btID(i))
Next
CreateGUID = Left$(CreateGUID, 8) & "-" & _
Mid$(CreateGUID, 9, 4) & "-" & _
Mid$(CreateGUID, 13, 4) & "-" & _
Mid$(CreateGUID, 17, 4) & "-" & _
Right$(CreateGUID, 12)
Else
CreateGUID = -1 'error result
End If

End Function


Sub test()

MsgBox CreateGUID()

End Sub


RBS


"Striker" wrote in message
...
My ultimate goal is to create an ID that will always be unique in column
"F". In that column I placed the following formula
=A2&""&B2&""&E2&""&C2.
I will need to do this on a daily basis, so would like to generate code to
do it for me at the push of a button. This can be any combination of
things. If you have a better idea to make a Unique ID column value, I'm
listening. However it MUST be unique even if the same data comes in
tomorrow, which is why I'm adding the date column.

(Spreadsheet Copy Attached) I also included a image of the sheet, in case
you're worried about a virus. Don't worry I changed all the numbers so
they
are not real numbers. This sheet is being passed to me, and I have to do
my
thing with it. I am currently even adding the date field and column
manually. So an added benefit would be to add that in code and make it a
text date like it is currently formatted so any leading "0" shows up.

My problem is the sheet can be up to 600 transactions, and I/I'm not sure
how to loop thru to find the last cell with good data.

So I'm Inserting a date column and populating with today's date as text
formatted as 051106
Inserting a UniqueID column and populating with a Unique ID down to the
last
cell with data (My problem, how to find the last cell with data when some
cells don't have data?)


Thanks for any help.










All times are GMT +1. The time now is 03:21 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com