Highlight duplicate rows on the spreadsheet

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

Please I have a spreadsheet with Columns A to AE, I need to find out the duplicate rows if the cells in columns B, C, D and F are matched with another row. I expect those duplicate rows should be highlighted in cell column A (not the whole row) for checking.

The spreadsheet has unknown total number of rows.

Please could anyone give me an idea how to create this macro? Many thanks.
 
I have replaced the line, the macro finished very quick but Column A content is all gone without any highlighted colour, also the filter on the first row is gone too.
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Column A content looks like concatenate of column B to F, The original content in A has all gone and no highlighted colour
 
Upvote 0
Can you provide some sample using XL2BB tool, so that proper solution can be provided
 
Upvote 0
How about this. Sorry about the confusion. I thought that Post #4 was a representative sample of your data. If this works for you, code could probably be added to trigger a MsgBox that tells you which rows are matches. See if this works first, before we jump to something else... The code should take about 30 seconds to run.

VBA Code:
Sub Find_Duplicates4()

    Dim arr, arr2, rng As Range
    Dim lRow As Long, j As Long, e As Long, i As Long
    
    Application.ScreenUpdating = False
    lRow = Sheets("Project").Cells(Rows.Count, "A").End(xlUp).Row
    Set rng = Range("A2:F" & lRow)
    arr = rng
    arr2 = rng
    For i = 1 To lRow - 1
        For j = 1 To lRow - 1
            If i + 1 > lRow - 1 Then
                Application.ScreenUpdating = True
                MsgBox "Operation Complete"
                Exit Sub
            End If
            If i = j Then j = j + 1
            If arr(i, 6) = arr2(j, 6) Then
                For e = 5 To 1 Step -1
                    If arr(i, e) <> arr2(j, e) Then Exit For
                Next
                rng.Cells(((i - 1) * 5 + i)).Interior.ColorIndex = 6
            End If
        Next
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Thanks igold. The macro picked up all rows with the same value in column F. However, I need to pick those duplicates having the same values in column B, C, D and F (not only F). I wonder is it possible to update the code?

Also I have added in 'MsgBox 9"Macro running is completed.") before End Sub so as to confirm the macro is completed. However only the MsgBox 'Operation Complete' appeared during the macro running.
 
Upvote 0
Thanks igold. The macro picked up all rows with the same value in column F. However, I need to pick those duplicates having the same values in column B, C, D and F (not only F). I wonder is it possible to update the code?

Also I have added in 'MsgBox 9"Macro running is completed.") before End Sub so as to confirm the macro is completed. However only the MsgBox 'Operation Complete' appeared during the macro running.
Msgbox "Macro running is completed", sorry for the typo above
 
Upvote 0
Have modified igold's code and you can try the below :

VBA Code:
Sub Find_Duplicates4()

    Dim arr, arr2, rng As Range
    Dim lRow As Long, j As Long, e As Long, i As Long
    
    Application.ScreenUpdating = False
    lRow = Sheets("Project").Cells(Rows.Count, "A").End(xlUp).Row
    Set rng = Range("A2:F" & lRow)
    arr = rng
    arr2 = rng
    For i = 1 To lRow - 1
        For j = 1 To lRow - 1
            If i + 1 > lRow - 1 Then
                Application.ScreenUpdating = True
                MsgBox "Operation Complete"
                Exit Sub
            End If
            If i = j Then j = j + 1
            If arr(i, 2) = arr2(j, 2) And arr(i, 3) = arr2(j, 3) And arr(i, 4) = arr2(j, 4) And arr(i, 6) = arr2(j, 6) Then
                For e = 5 To 1 Step -1
                    If arr(i, e) <> arr2(j, e) Then Exit For
                Next
                rng.Cells(((i - 1) * 5 + i)).Interior.ColorIndex = 6
            End If
        Next
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
you could just concat the data from BCD&F into a cell and then trim and clean the values
Book1
BCDEFG
1ColBColCColDColEColFConCat
2266h7266h7
3356j8356j8
4f146of146o
5g365hg365h
6356j8356j8
71d36f1d36f
Sheet1
Cell Formulas
RangeFormula
G2:G7G2=TRIM(CLEAN(CONCAT(B2:F2)))

Then just use
Excel function under Dat to remove Duplicates
1659687914437.png
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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