I don't have a database anywhere near as large as what you indicated you will be working with, so I cannot test the speed difference out between the code I posted earlier (which should be about as fast as you will be able to find), but it is possible that the code below will execute even faster. You should make a copy of your workbook and test both out, using whichever one executes quicker for you.
Code:
Sub MarkPositionNumbers2()
Dim X As Long, Z As Long, LastUniqueRow As Long, LastDataRow As Long
Dim Uniques As Variant, Data As Variant, Positions As Variant
Const DataColumn As String = "G"
Const UniqueColumn As String = "A"
Const FirstUniqueRow As Long = 2
LastDataRow = Cells(Rows.Count, DataColumn).End(xlUp).Row
LastUniqueRow = Cells(Rows.Count, UniqueColumn).End(xlUp).Row
Uniques = Cells(FirstUniqueRow, UniqueColumn).Resize(LastUniqueRow - FirstUniqueRow + 1)
Data = Cells(1, DataColumn).Resize(LastDataRow)
ReDim Positions(LBound(Data) To UBound(Data), 1 To 1)
For X = LBound(Uniques) To UBound(Uniques)
For Z = LBound(Data) To UBound(Data)
If Uniques(X, 1) = Data(Z, 1) Then Positions(Z, 1) = X - LBound(Uniques) + 1
Next
Next
Application.ScreenUpdating = False
Cells(1, DataColumn).Offset(, 1).Resize(LastDataRow) = Positions
Application.ScreenUpdating = True
End Sub
Note 1: Unlike my previously posted code, this macro will work whether the Data values are constants or the result of formulas.
Note 2: You should look at the three Const statements and make sure the values I assign to them matches your actual setup.
Bookmarks