Hi. I have a macro that I use to go through each record's ID number and check to see if that number is in the list and if so, it will return how many times it is in the list in the adjacent column. This works great on many of the spreadsheets that we use it for, but there is a group of spreadsheets that have over 800,000 records where it takes a long time to process through (over 9 hours!) I have tried multiple methods in the past from applying the countif formula directly to each row and letting excel do the heavy lifting (resulted in not all formulas calculating and an incorrect result), using a scripting dictionary (took about 4 hours but didn't return the count of the occurrences and ignored the first instance of each), to conditional formatting (which highlighted every duplicate supposedly but I was never able to check because afterwards the sheet would become unusable and freeze). Here is my existing code. Any help would be greatly appreciated.
VBA Code:
Application.ScreenUpdating = False
StepNum = StepNum + 1
Application.StatusBar = "Validating Duplicate Case IDs (Step " & StepNum & " of 12)"
ActiveSheet.AutoFilterMode = False
DoEvents
rApplication.Offset(0, 1).Select
If Cells(rHdr.Row, ActiveCell.Column) = "Application Count" Then
Else
Trulcol = Trulcol + 1
rCase.Offset(0, 1).EntireColumn.Insert
rCase.Offset(0, 1).EntireColumn.NumberFormat = "General"
rCase.Offset(0, 1).EntireColumn.Interior.Color = 65535
Cells(rHdr.Row, rCase.Column + 1) = "Case Count"
End If
rApplication.Offset(0, 1).Select
''''Goes one by one and takes forever (9 hours) 100% Accurate
Set ra1 = Cells(rHdr.Row, ActiveCell.Column)
Do
Set ra1 = ra1.Offset(1, 0)
Application.StatusBar = "Validating Duplicate Case IDs (Step " & StepNum & " of 12) " & ra1.Row & " of " & Trulrow
ra1.Value = Application.WorksheetFunction.CountIf(Range(rApplication.Address), ra1.Offset(0, -1))
Loop Until ra1.Row = Trulrow