Compare 2 Cols and Highlight if >NOT< Found

ChrisOK

Well-known Member
Joined
Mar 26, 2003
Messages
601
In one workbook, need to do a simple VBA match like this:
Compare Col B (starting with row 8) of the PARTS tab to Col P (starting w/ row 5) of the MATERIALS tab.
If match is found, do nothing, (continue to next row)... if NO MATCH is found, then highlight/fill the cell in COL P of the MATERIALS tab with red.

Continue until every item on the PARTS tab column B has been compared.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Code:
Sub notFound()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range, c As Range
Set sh1 = Sheets("PARTS")
Set sh2 = Sheets("MATERIALS")
lr = sh2.Cells(Rows.Count, "P").End(xlUp).Row
Set rng = sh2.Range("P5:P" & lr)
    For Each c In rng
        If Application.CountIf(sh1.Range("B8", sh2.Cells(Rows.Count, "B"). _
        End(xlUp)), c.Value) = 0 Then
            c.Interior.ColorIndex = 3
        End If
    Next
End Sub
 
Upvote 0
for some reason, I keep getting a Run-time error 1004: Method Range' of object_Worksheet failed' error and this portion of code is highlighted:
Code:
        If Application.CountIf(sh1.Range("B8", sh2.Cells(Rows.Count, "B"). _
        End(xlUp)), c.Value) = 0 Then

any ideas?
 
Upvote 0
for some reason, I keep getting a Run-time error 1004: Method Range' of object_Worksheet failed' error and this portion of code is highlighted:
Rich (BB code):
        If Application.CountIf(sh1.Range("B8", sh2.Cells(Rows.Count, "B"). _
        End(xlUp)), c.Value) = 0 Then

any ideas?

Typo on my part, should be:
Code:
If Application.CountIf(sh1.Range("B8", [COLOR=#ff0000]sh1[/COLOR].Cells(Rows.Count, "B"). _
        End(xlUp)), c.Value) = 0 Then
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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