Find Duplicates & highlight row

danushka

Well-known Member
Joined
Sep 6, 2009
Messages
693
Dear friends in my excel sheet base on column "D" i want find all Duplicate & highlight that whole row in yellow.......pls make macro for this..i need only run this macro in my section.i don't want to find whole duplicates in column "D"...

ex- if i select A5 to K50 then this macro should run on that range only....

pls help me.thanks in advance......
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try

Code:
Sub Dups()
Dim iRow As Long, nRow As Long, iCol As Long, nCol As Long
Dim i As Long
iCol = Selection.Column
nCol = iCol + Selection.Columns.Count - 1
iRow = Selection.Row
nRow = iRow + Selection.Rows.Count - 1
For i = iRow To nRow
    If WorksheetFunction.CountIf(Range(Cells(iRow, 4), Cells(nRow, 4)), Cells(i, 4)) > 1 Then
        Range(Cells(i, iCol), Cells(i, nCol)).Interior.ColorIndex = 6
    End If
Next i
End Sub
 
Upvote 0
Try

Code:
Sub Dups()
Dim iRow As Long, nRow As Long, iCol As Long, nCol As Long
Dim i As Long
iCol = Selection.Column
nCol = iCol + Selection.Columns.Count - 1
iRow = Selection.Row
nRow = iRow + Selection.Rows.Count - 1
For i = iRow To nRow
    If WorksheetFunction.CountIf(Range(Cells(iRow, 4), Cells(nRow, 4)), Cells(i, 4)) > 1 Then
        Range(Cells(i, iCol), Cells(i, nCol)).Interior.ColorIndex = 6
    End If
Next i
End Sub
wow thanks a lot sir.it's work very well........:):):)
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,159
Members
452,892
Latest member
yadavagiri

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