How to make different sorts of duplicates have different color?

Klash Ville

Board Regular
Joined
Sep 19, 2017
Messages
83
Currently I have this code that with the support of conditional formatting, is able to detect all duplicates, but makes them have the same exact color. This is a problem because I have a gigantic table and looking at everything with the same color.

Code:
    Range("Table2[[#Headers],[Plastic (kg)]]").Select
    Selection.ListObject.ListColumns.Add
    Range("Table2[[#Headers],[Column1]]").Select
    ActiveCell.Offset(1, 0).Activate
    ActiveCell.FormulaR1C1 = _
        "=RC[-19]&RC[-17]&RC[-15]&RC[-14]&RC[-13]&RC[-12]&RC[-11]&RC[-10]&RC[-9]&RC[-8]&RC[-7]&RC[-6]&RC[-5]&RC[-4]&RC[-3]&RC[-2]&RC[-1]"
    Range("Table2[Column1]").Select


    Selection.FormatConditions.AddUniqueValues
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).DupeUnique = xlDuplicate
    With Selection.FormatConditions(1).Font
        .Color = -16383844
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13551615
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False


    With ActiveWorkbook.Worksheets("Feuil1").ListObjects("Table2").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveSheet.ListObjects("Table2").Range.AutoFilter Field:=20, Criteria1:= _
        RGB(255, 199, 206), Operator:=xlFilterCellColor
    
    Range("Table2").Select
    ActiveCell.Offset(1, 0).Activate
    Do While ActiveCell.EntireRow.Hidden = True
    ActiveCell.Offset(1, 0).Activate
    Loop
    If Not IsEmpty(ActiveCell) Then
    Range(Selection, Selection.End(xlDown)).Select
    With Selection.Interior
        .PatternColorIndex = xlAutomatic
        .Color = 65535
    End With
    End If
    
    Range("Table2[[#Headers],[Column1]]").Select
    ActiveCell.Offset(0, -1).Activate
    ActiveCell.Offset(1, 0).Activate
    Do While ActiveCell.EntireRow.Hidden = True
    ActiveCell.Offset(1, 0).Activate
    Loop
    If ActiveCell.Interior.ColorIndex = 6 Then
        Columns("T:T").Select
        Selection.Delete Shift:=xlToLeft
        Range("A1").Select
        
        If MsgBox("Duplicated rows have been found, do you wish to ignore them?", vbCritical + vbYesNo) = vbNo _
        Then
            MsgBox "The macro will now come to an halt in order for you to re-check your data.", vbInformation
            Exit Sub
        End If
    End If
    
    Columns("T:T").Select
    Selection.Delete Shift:=xlToLeft
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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