beartooth91
New Member
- Joined
- Dec 15, 2024
- Messages
- 9
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
VBA Code:
Sub Check_Duplicates3()
'
Dim ws As String, i As Long, FinalRow As Long, Main As Worksheet, rr As Range, r As Range
ws = InputBox(Prompt:="Enter the worksheet name to check", _
Title:="Enter Worksheet Name", Default:="AST")
Set Main = ThisWorkbook.Sheets(ws)
FinalRow = Main.Range("B" & Rows.Count).End(xlUp).Row
Set rr = Main.Range("B11:B" & FinalRow)
For Each r In rr
If WorksheetFunction.CountIf(rr, r.Value) > 1 Then
r.EntireRow.Interior.ColorIndex = 6
MsgBox ("You have duplicate point names. Please review the highlighted rows.")
Else
MsgBox ("No duplicate point names found.")
GoTo LastLine
End If
Next r
LastLine:
Main.Activate
End Sub
It works perfectly when the Else block is NOT present.
When I include the Else block; it jumps right to that block, even if there are duplicate values.
Tried some different things with no success. I'm not sure what I'm doing wrong. Should be a standard If-Then-Else statement......?