I am trying to find duplicate data in a column with user input. I have tried the countif in vba it works if i tell it the range i want like (If Application.Worksheet.CountIf(Range("M2:M" & D), Range("M" & D)) > 1 Then), but if i use a name range from of the user selection i cant get it to work. I am new to this still and trying to learn but hit road blocks like this all of the time.
Here is the code:
Sub CheckDup()
'
' CheckDup Macro
'
'
Dim D As Long
Dim finalrow As Long
Dim rRange As Range
finalrow = ActiveSheet.UsedRange.Rows.Count
Count = 1
For D = 2 To finalrow
If Cells(D, 13).Value = 0 Then
Else
On Error Resume Next
Application.DisplayAlerts = False
Set rRange = Application.InputBox(Prompt:= _
"Please select a Column with your Mouse to be Checked.", _
Title:="SPECIFY RANGE", Type:=2)
On Error GoTo 0
If Application.Worksheet.CountIf(Range(rRange & D), Range(rRange & D)) > 1 Then
Cells(D, rRange).Resize(1, 1).Interior.ColorIndex = 5
End If
End If
Next D
End Sub
I am trying to do this because the data moves from column to column depending on the user.
Any help would be great
Here is the code:
Sub CheckDup()
'
' CheckDup Macro
'
'
Dim D As Long
Dim finalrow As Long
Dim rRange As Range
finalrow = ActiveSheet.UsedRange.Rows.Count
Count = 1
For D = 2 To finalrow
If Cells(D, 13).Value = 0 Then
Else
On Error Resume Next
Application.DisplayAlerts = False
Set rRange = Application.InputBox(Prompt:= _
"Please select a Column with your Mouse to be Checked.", _
Title:="SPECIFY RANGE", Type:=2)
On Error GoTo 0
If Application.Worksheet.CountIf(Range(rRange & D), Range(rRange & D)) > 1 Then
Cells(D, rRange).Resize(1, 1).Interior.ColorIndex = 5
End If
End If
Next D
End Sub
I am trying to do this because the data moves from column to column depending on the user.
Any help would be great