VBA Help With Multiple Condition "IF" Statement

DA7135X

New Member
Joined
Apr 3, 2012
Messages
3
I need some help writing a visual basic code that says,
"If a cell in column B = "H" and
the corresponding cell in column C = 0, then
change the value in column C from 0 to HLB.

As I am very new to VBA, the simpler the answer the better. Appreciate any help anyone can give.
Thank you.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = 0 And .Offset(, -1).valoe = "H" Then .Value = "HLB"
    End With
Next i
End Sub
 
Upvote 0
Hi Peter, thank you so much for your quick response. I am receiving the following error message in regards to the "IF" line and I am not sure how to correct.
"Object does not support property or method".
 
Upvote 0
Sorry, typo

Code:
Sub atest()
Dim LR As Long, i As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    With Range("C" & i)
        If .Value = 0 And .Offset(, -1).Value = "H" Then .Value = "HLB"
    End With
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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