Color duplicates rows in two different sets of data and also the rows which are present in both sets of data.

Noob_Excel

New Member
Joined
Aug 22, 2022
Messages
1
Office Version
  1. 2013
Platform
  1. Windows
Note - When I say rows, I mean cells in column A only and not the whole row.

Background

There are two sets of data. Lets call the data on the top, Data A and data on the bottom, Data B

I have made a Macro (VBA provided at the bottom) that:
1. Clears the Conditional Formatting on the entire sheet.
2. Highlights all duplicate rows as Red.
3. Highlights all duplicate rows in Data A as Green.
4. Highlights all non-empty cells in Column E as Yellow.
5. Sorts Data A in the following order. Red cells in Column A, Green cells in Column A, Yellow cells in Column E, Column A Values Ascending, Column D Values Ascending.

In simple words it;
a) marks duplicate rows present in both Data A & Data B as red
b) marks duplicate rows of Data A as Green.

In the image below: Data A(A6:A8)=Data B(A18,A20) Data A(A9:A10)=Data B(A19) Data A(A4:A5)

Question

Now I want the Macro to work this way:
1) Duplicate rows of whole data should be Highlighted Red
2) Duplicate rows in Data A that are also present in Data B should all be Highlighted Blue
3) Duplicate rows present only in Data A should be Highlighted Green
4) Any non-blank cells in Column E should be Yellow

Sample Data Image

Personal.xlsb
ABCDE
1 661-067-6333 2020 honda civic17,900Los angelestitle status salvage
2 661-585-8368 2002 Buick Lesabre2,800Grand Rapids
3 998-216-0204 2003 chevrolet silverado3,200Perrinton
4 226-017-1780 2006 HONDA ACCORD3,900Rochester hilltitle status Lemon
5 226-017-1780 2019 Chevrolet Silverado 3500 LT48,500West Bend
6 568-072-2522 2007 Chevrolet HHR LT4,200Sterling Heights
7 568-072-2522 1999 Ford Ranger3,300Sterling Heights
8 568-072-2522 2006 Toyota Camry XLE2,999Sterling Heights
9 737-958-0293 2015 Jeep Grand Cherokee21,700Fenton
10 737-958-0293 2016 Chevrolet Equinox V616,900Trevor WI nearby Antioch IL
11 662-134-8725 2020 honda civic ex hatchback17,900Antioch ILtitle status salvage
12 213-407-9351 2008 Chrysler PT cruiser6,850montague
13 242-488-0805 2003 HONDA ACCORD V6 EX-L3,200schiller
14 284-877-4409 2010 chevrolet silverado 150011,250WEST BLOOMFIELD
15
16
17 568-072-2522 2006 toyota camry2999Sterling Heights
18 737-958-0293 2013 toyota prius2999Fenton
19 568-072-2522 2008 ford f-1505900Sterling Heightstitle status rebuilt
20 616-108-5898 1999 oodge Ram 2500 2W02800Grand Rapids
21 998-216-0204 2006 Honda Accord3200Perrinton
22 881-884-6206 2018 Nissan Rogue12900Sun valley
23 661-067-6333 2014 Ford explorer XLT8750Trevor WItitle status salvage
24 801-229-4503 2009 Audi A34900Simi Valley
25 616-695-0075 2005 Honda Accord1500Tehachapi
26 616-013-8792 Nissan Frontier 2004 extra cab4800Santa Clarita
27 616-013-8792 2014 Ford Taurus Police Intercepter10200Bakersfield
28 661-585-8368 2002 Buick Lesabre11000Grand Rapids
29 973-765-4366 2006 land rover range rover7600charlotte
30 595-304-9290 2008 Chrysler PT cruiser4000Fresnotitle status lemon
31 526-467-3561 2000 Toyota 4Runner5850Long Beachtitle status rebuilt
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E1:E31Expression=LEN(TRIM(E1))>0textNO
A1:A14Cell ValueduplicatestextNO
A:ACell ValueduplicatestextNO


[Sample Data](https://i.stack.imgur.com/QzQc3.png)

This is the VBA of my Macro:

VBA Code:
'
'
'Declaration
'
'
    Dim MyRange As String
    Dim Rough As String
    Dim A_To_Q As String
    Dim A_To_E As String
    Dim A_To_F As String
    Dim ColumnA As String
    Dim ColumnC As String
    Dim ColumnD As String
    Dim ColumnE As String
    Dim ColumnF As String
'
'
'Assignment
'
'
    MyRange = ActiveCell.Address(0, 0) & ":" & "E1"
'
    Rough = ActiveCell.Offset(0, -2).AddressLocal & ":" & "Q1"
    A_To_Q = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, -2).Address & ":" & "E1"
    A_To_E = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, -2).Address & ":" & "F1"
    A_To_F = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, -2).Address & ":" & "A1"
    ColumnA = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, 0).Address & ":" & "C1"
    ColumnC = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, 1).Address & ":" & "D1"
    ColumnD = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, 2).Address & ":" & "E1"
    ColumnE = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
    Rough = ActiveCell.Offset(0, 3).Address & ":" & "F1"
    ColumnF = Mid(Rough, 2, 1) & Mid(Rough, 4, 6)
'
'
'Formating
'
'
    Cells.FormatConditions.Delete
'
    Columns("A:A").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
'
    Range(ColumnA).Select
    Selection.FormatConditions.AddUniqueValues
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).DupeUnique = xlDuplicate
    With Selection.FormatConditions(1).Font
        .Color = -16752384
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 13561798
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
'
    Range(ColumnE).Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=LEN(TRIM(E1))>0"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Color = -16751204
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 10284031
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
'
'
'Sorting
'
'
Range(A_To_F).Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range(ColumnA), _
        xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
        199, 206)
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range(ColumnA), _
        xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(198, _
        239, 206)
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range(ColumnE), _
        xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
        235, 156)
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(ColumnA) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range(ColumnD) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range(A_To_F)
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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