Highlite Duplicates in Range

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,428
I know I can do this with CF, but CF wont work because when I paste to HMTL I loose formatting.

Trying to Highlite Duplicates in Range via VBA.

Code:
For r = 5 To 10
myRange = Range(Cells(r, "D"), Cells(r, "H"))

For Each cell In myRange
    If WorksheetFunction.CountIf(myRange, cell.Value) > 1 Then cell.Interior.ColorIndex = 6
Next cell
Next r

Thanks for looking,

Ross
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try

Rich (BB code):
Dim cell As Range, MyRange As Range
For r = 5 To 10
    Set MyRange = Range(Cells(r, "D"), Cells(r, "H"))
    For Each cell In MyRange
        If WorksheetFunction.CountIf(MyRange, cell.Value) > 1 Then cell.Interior.ColorIndex = 6
    Next cell
Next r
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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