Identifying Matching Values Between 2 Sheets and Retaining Formatting When Sorting

mrscottjr

New Member
Joined
Jul 24, 2015
Messages
41
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good evening!

I have multiple sheets in my workbook. Sheets("Setup") and Sheets("Data") are the two sheets I'm looking to compare to find matching values. If any of the the values in Column C of the "Setup" sheet are found in Column E of the "Data" sheet, I'd like to highlight the cell green on the "Setup" sheet.

Unfortunately I'm also having difficulty with those highlighted matching cells retaining the color formatting when the "Setup" sheet is is sorted/filtered.

Any assistance would be great!
 

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
If the autofilter is not being removed from the Setup sheet, sorting should keep colors intact.

As for the matching, I think that's a VBA solution (someone might be able to hookup a VLOOKUP in conditional formatting or something).
Code:
Sub ValueMatching()
    Dim finalRow As Integer
    Dim i As Integer
    Dim x As Range
    
    finalRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For i = 2 To finalRow
        On Error Resume Next
        Set x = Sheets("Data").Columns(5).Find(What:=Cells(i, 3).Value, After:=Sheets("Data").Cells(1, 1), _
            LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=True)
        On Error GoTo 0
        
        If Not x Is Nothing Then
            Cells(i, 3).Interior.Color = 5880731
        End If
    Next i
End Sub
 
Upvote 0
Thanks for the response! Unfortunately I'm not getting any hits for a match when I know there are handful....
 
Last edited:
Upvote 0
Since I can't see and test the results, there are two ways I'd suggest troubleshooting this. The first is to use message boxes to help you inspect what is going on, counting how many matches are found or just to ID the values it's looking at (maybe the references are off). The other is to step through the code and inspect the ones you know have a match. Maybe the matches aren't exact matches.

If I had to take a guess, I'd say the references are off on the Find function. I didn't put the sheet name on the What:= parameter, so maybe it's looking at column C on the Data sheet instead of the Setup sheet.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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