I had a requirement to check for the presence of duplicates in a column in Excel.
I have written a function for this purpose and it works. The drawback is that it is an extremely slow function and takes about 6 minutes to check across 20000 rows. Could someone take a look and speed up the function?
VB Code:
Sub CheckDuplicate() Dim txtSearchVal As String Dim lCtr As Long Dim lCtr2 As Long Dim bFound As Boolean For lCtr2 = 1 To 20000 txtSearchVal = Sheet1.Cells(lCtr2, 1) For lCtr = (lCtr2 + 1) To 20000 If Sheet1.Cells(lCtr, 1) = txtSearchVal Then Sheet1.Cells(lCtr, 1).Font.Color = vbRed Sheet1.Cells(lCtr, 1).Font.Bold = True 'Sheet1.Cells(lCtr, 1).AddComment ("Duplicate Values") Exit For End If Next lCtr Next lCtr2 End Sub




Reply With Quote