M
Mekinnik
I copied and edited this code to find duplicate names in my worksheet column
B and then display a msgbox to tell the user so, however it is not working at
all. Please advise
Sub FindDuplicates()
Dim colNum As String
Dim rng As Range, cell As Range
Dim rng1 As Range
colNum = "B"
With ActiveSheet
Set rng = .Range(.Cells(1, colNum), .Cells(Rows.Count, colNum).End(xlUp))
End With
For Each cell In rng
If Application.CountIf(rng, cell) > 1 Then
If rng1 Is Nothing Then
Set rng1 = cell
Else
Set rng1 = Union(rng1, cell)
End If
End If
Next
If Not rng1 Is Nothing Then
MsgBox "YOU HAVE ENTERED A DUPLICATE MANUFACTURER NAME"
End If
End Sub
B and then display a msgbox to tell the user so, however it is not working at
all. Please advise
Sub FindDuplicates()
Dim colNum As String
Dim rng As Range, cell As Range
Dim rng1 As Range
colNum = "B"
With ActiveSheet
Set rng = .Range(.Cells(1, colNum), .Cells(Rows.Count, colNum).End(xlUp))
End With
For Each cell In rng
If Application.CountIf(rng, cell) > 1 Then
If rng1 Is Nothing Then
Set rng1 = cell
Else
Set rng1 = Union(rng1, cell)
End If
End If
Next
If Not rng1 Is Nothing Then
MsgBox "YOU HAVE ENTERED A DUPLICATE MANUFACTURER NAME"
End If
End Sub