Generate GUID, Find Duplicates, Replace, Rescan

  • Thread starter christopher wooley
  • Start date
C

christopher wooley

I am trying to find a way to generate GUIDs, which I've found, but I
need to ensure they are truly unique. Here is the script that
generates the GUIDs

Sub GenerateGUID()

Dim c As Long, r As Range
c = 1
Set r = Range("a2")

Do Until r.Cells(c, 1) = ""

Dim strGUID As String
Set TypeLib = CreateObject("Scriptlet.TypeLib")
strGUID = Left(TypeLib.GUID, 38)



r.Cells(c, 16).Value = strGUID
c = c + 1



Set TypeLib = Nothing

Loop
End Sub


Here is the script that scans for duplicates. I need a couple changes,
but I don't know how to do them. First, I need it to generate the
GUIDs with the above script. I'm guessing that can be a separate
process. Second, I need it to scan the list (column) it just made. If
it finds a duplicate, I need it to replace the entry with another
GUID, not delete it. Once it regenerates, I need it to rescan the list
from the beginning, finishing out with truly, verified, unique IDs.


Sub DelDups_OneList()
Dim iListCount As Integer
Dim iCtr As Integer

' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False

' Get count of records to search through.
iListCount = Sheets("Sheet1").Range("A1:A100").Rows.Count
Sheets("Sheet1").Range("A1").Select
' Loop until end of records.
Do Until ActiveCell = ""
' Loop through records.
For iCtr = 1 To iListCount
' Don't compare against yourself.
' To specify a different column, change 1 to the column number.
If ActiveCell.Row <> Sheets("Sheet1").Cells(iCtr, 1).Row Then
' Do comparison of next record.
If ActiveCell.Value = Sheets("Sheet1").Cells(iCtr, 1).Value
Then
' If match is true then delete row.
Sheets("Sheet1").Cells(iCtr, 1).Delete xlShiftUp
' Increment counter to account for deleted row.
iCtr = iCtr + 1
End If
End If
Next iCtr
' Go to next record.
ActiveCell.Offset(1, 0).Select
Loop
Application.ScreenUpdating = True
MsgBox "Done!"
End Sub

Thanks for the help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top