Highlite duplicates with different colours

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I am trying to modify this code from the excel forum to highlite dupplicate but with using a pop up box to specifly the column first

Keeps bugging out on Set myrng = Range(c)

Sub Find_Duplicate()
Dim cel As Variant
Dim myrng As Range
Dim clr As Long
Dim c As String
Dim LastRow As Long
Dim x As Long

c = InputBox("Enter column letter", "Remove Duplicates", "A")
If c = "" Then Exit Sub
LastRow = Range(c & Rows.Count).End(xlUp).Row


Set myrng = Range(c)
myrng.Interior.ColorIndex = xlNone
clr = 3
For Each cel In myrng
If Application.WorksheetFunction.CountIf(myrng, cel) > 1 Then
If WorksheetFunction.CountIf(Range("K2:K" & cel.Row), cel) = 1 Then
cel.Interior.ColorIndex = clr
clr = clr + 1
Else
cel.Interior.ColorIndex = myrng.Cells(WorksheetFunction.Match(cel.Value, myrng, False), 1).Interior.ColorIndex
End If
End If
Next
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
In your statement:

Code:
Set myrng = Range(c)

"c" is not a range. It is merely the string you entered in the input box. You must make it something like this:

Code:
Set myrng = Range(c & "2" & ":" & c & LastRow)

The number 2 being the starting row

Hope that helps.

Gary
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top