I coded the below script to have Excel exit a sub if it finds duplicates in a row. However, when it runs, it tells performs the else function for n times there is no duplicate.
What I thought it would do is scrub column F for duplicates and display the duplicate message then exit the sub.
If there are no dupes, I only want the else section performed one time (not every time there is not a duplicate).
Any ideas?
What I thought it would do is scrub column F for duplicates and display the duplicate message then exit the sub.
If there are no dupes, I only want the else section performed one time (not every time there is not a duplicate).
Code:
Sub mcrCheckDup()
Dim r As Range
Dim n As Long
Dim RowCount As Long
Range("F2").Select
Set r = Range(Selection, Selection.End(xlDown))
For n = 1 To r.Rows.Count
If r.Cells(n, 1) = r.Cells(n + 1, 1) Then
MsgBox "Duplicate Data", [vbExclamation]
Exit Sub
Else: MsgBox "ok"
End If
Next n
End Sub
Any ideas?