Is This VBA ElseIf Logic Correct - I Am Still Learning - Thank You!

kescco

Board Regular
Joined
Sep 14, 2009
Messages
174
Okay, I am hoping this code is correct.

What I am hoping for is the following.

IF C is 541 AND
B is 1000, 2000, or 3000
Then C is 541-NotCanton

Code:
ElseIf Range("C" & i).Value = 541 And _
(Range("B" & i).Value = 1000 Or _
Range("B" & i).Value = 2000 Or _
Range("B" & i).Value = 3000) Then
Range("C" & i).Value = "541-NotCanton"
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Do you have an If construct before this and End If after? This statement looks ok, but will work only with a complete If Then - ElseIf Then - End If construct.
If you want to just write an If statement then change it to

Code:
If Range("C" & i).Value = 541 And _
        (Range("B" & i).Value = 1000 Or _
        Range("B" & i).Value = 2000 Or _
        Range("B" & i).Value = 3000) Then
    Range("C" & i).Value = "541-NotCanton"
End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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