vba code Highlight Cells if equal to adjacent cell

ARL

New Member
Joined
Jun 26, 2020
Messages
6
Office Version
  1. 365
Platform
  1. Windows
What I’m looking for is a code that will highlight (Yellow Fill) all the non-blank cells in Column B, if there is a non-blank value in the adjacent cell in Column C.

E.g.
If Cell B10 has a value & cell C10 has a value that is equal to "PICKUP" – Then Yellow fill cell B10
If Cell B15 has a value & cell C15 has a value that is equal to "X" - Then No Fill cell B15
If Cell B232 has a value & cell C232 has a value that is equal to "PICKUP" – Yellow fill cell B232
Ignore if no match

Currently 'B' column has a VBA Code as follows =IF(COUNTIF($A:$A,$B9)=0,"X","PICKUP")

Because I have a Header Row, presumably it would need to find and use the range between B9 and the last cell used in Column B

I would like to have just an extra piece of VBA code that would complete this action.

Currently I am running the following code, but it is Highlighting the fields with the wrong information in it, and I just can't figure it out.

Sub HighlightCells()

Dim c As Range
For Each c In Range("B9", Range("B" & Rows.Count).End(xlUp))
If c <> "" And c.Offset(, 1) <> "" Then
c.Interior.Color = 65535
End If
Next c
End Sub

Thank you.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How about:

VBA Code:
Sub HighlightCells()
  Dim c As Range
  For Each c In Range("B9", Range("B" & Rows.Count).End(xlUp))
    If c <> "" And c.Offset(, 1) = "PICKUP" Then
      c.Interior.Color = 65535
    End If
  Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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