ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
Morning,
The code supplied below alerts me of a Duplicate no problem at all.
But if no Duplicates are found i dont see a message to say No duplicates found etc.
So i tried the code below but its incorrect,can you advise please the correct code.
Thanks.
The code supplied below alerts me of a Duplicate no problem at all.
Code:
Private Sub CommandButton2_Click()
Dim cell As Range
With Intersect(ActiveSheet.Columns("A"), ActiveSheet.UsedRange)
For Each cell In .Cells
If WorksheetFunction.CountIf(.Resize(cell.Row - .Rows(1).Row + 1), cell.Value) > 1 Then MsgBox "Duplicate Item Number " & cell.Value & " in cell " & cell.Address(False, False), vbCritical, "DUPLICATE ITEM NUMBER CHECKER"
Next cell
End With
End Sub
But if no Duplicates are found i dont see a message to say No duplicates found etc.
So i tried the code below but its incorrect,can you advise please the correct code.
Thanks.
Code:
Private Sub CommandButton2_Click() Dim cell As Range
With Intersect(ActiveSheet.Columns("A"), ActiveSheet.UsedRange)
For Each cell In .Cells
If WorksheetFunction.CountIf(.Resize(cell.Row - .Rows(1).Row + 1), cell.Value) > 1 Then MsgBox "Duplicate Item Number " & cell.Value & " in cell " & cell.Address(False, False), vbCritical, "DUPLICATE ITEM NUMBER CHECKER"
Next cell
Else
MsgBox "No Duplicate Items Were Present", , "DUPLICATE ITEM NUMBER CHECKER"
End If
End With
End Sub