VBA If's on multiple columns

stevenm

New Member
Joined
Apr 23, 2012
Messages
18
Hi All,

Trying to write a VBA macro that runs down column A and if it has a value then checks to see if column B has content and if it doesn't highlights the cell in B a color.

Below is my example:

Excel 2010
AB
1Value 1Value 2
2abc123xyz
3abc124xyz
4abc125xyz
5abc126
6abc127xyz
7abc128xyz
8abc129
9abc130xyz
10abc131xyz
11abc132xyz
12abc133xyz
13abc134xyz
14abc135
Sheet1


Ideally Id like the result of running the macro to be that cells B5, B8 and B14 all become highlighted in orange.

Any help is appreciated.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    With Range("A" & i)
        If .Value <> "" And .Offset(, 1).Value = "" Then .Offset(, 1).Interior.ColorIndex = 44
    End With
Next i
End Sub
 
Upvote 0
Hi VoG,

Thanks for quick reply - thought Id post the question then head home from work. Only managed to go get into my riding gear and by the time I got back to my desk you delivered an answer that I just tested and works 100% as I want it to.

Again many thanks.

Steve
 
Upvote 0

Forum statistics

Threads
1,215,181
Messages
6,123,508
Members
449,101
Latest member
mgro123

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