Find duplicate rows

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have a workbook with multiple tabs, I need to find out duplicate rows in the sheets One to Five if the cells in columns B, D and F on the rows are the same. Duplicate rows should be highlighted for manual deletion.

I have searched some code below, however they are compared from column A to F but indeed only B, D and F are required to compare only. Anyway they don't work probably.

Please could any one help. Many thanks.

VBA Code:
Sub Find_Duplicate_Rows()


Dim arrSheets As Variant, sh As Variant, LRow As Long, i As Variant, r As Long

arrSheets = Array("One", "Two", "Three", "Four", "Five")

LRow = sh.Cells(Rows.Count, "A").End(xlUp).Row

For Each sh In arrSheets
 
Dim cRange As Range
    Dim cSearch As Range
    Dim acSearch As String
    Dim cDuplicate As String
    Dim x As Integer
    Dim name As String
    Range("A2:F" & LRow).Interior.Pattern = xlNone
    cColor = 6
    Set cRange = Range("A2:F" & LRow)
    For Each i In cRange
        x = WorksheetFunction.CountIf(Columns(2), i) - 1
        If x > 0 Then
            cDuplicate = i & i.Offset(0, 1).Value & i.Offset(0, -1).Value
            Set cSearch = i
            For x = 1 To x
                Set cSearch = cRange.Find(What:=i, After:=cSearch, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
                acSearch = cSearch.Address
                If cDuplicate = Range(acSearch).Value & Range(acSearch).Offset(0, 1).Value & Range(acSearch).Offset(0, -1).Value Then
                    With Union(Range(acSearch), Range(acSearch).Offset(0, 1), Range(acSearch).Offset(0, -1), i, i.Offset(0, 1), i.Offset(0, -1)).Interior
                        .ColorIndex = cColor
                    End With
                End If
            Next x
        End If
        cColor = cColor + 1
    Next i

Next sh



End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,223,228
Messages
6,170,871
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