H
Horatio J. Bilge, Jr.
I wrote some code to check a column for duplicates. If duplicates are found,
a message box shows that the column has duplicate values. I want to expand
the code to include multiple columns, so the message box will then list all
of the columns that have duplicates. My code checks column B - I want to also
check C through M. The data is in rows 3 - 42, and column headers are in row
2.
Here is my code:
Sub DupeCheck()
Dim r As Integer
Dim m As String
For r = 42 To 3 Step -1
If Cells(r, "B").Value = "" Then
GoTo EmptyCell
End If
If Application.WorksheetFunction.CountIf(Range("B1:B" & r), Range("B" &
r).Text) > 1 Then
m = m & vbLf & Cells(2, "B").Value
Exit For
End If
EmptyCell:
Next r
MsgBox "These columns have duplicates: " & vbLf & m
End Sub
a message box shows that the column has duplicate values. I want to expand
the code to include multiple columns, so the message box will then list all
of the columns that have duplicates. My code checks column B - I want to also
check C through M. The data is in rows 3 - 42, and column headers are in row
2.
Here is my code:
Sub DupeCheck()
Dim r As Integer
Dim m As String
For r = 42 To 3 Step -1
If Cells(r, "B").Value = "" Then
GoTo EmptyCell
End If
If Application.WorksheetFunction.CountIf(Range("B1:B" & r), Range("B" &
r).Text) > 1 Then
m = m & vbLf & Cells(2, "B").Value
Exit For
End If
EmptyCell:
Next r
MsgBox "These columns have duplicates: " & vbLf & m
End Sub