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"
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

V_Malkoti

Well-known Member
Joined
Jun 10, 2015
Messages
898
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:

Watch MrExcel Video

Forum statistics

Threads
1,123,487
Messages
5,601,961
Members
414,486
Latest member
Darkai

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
Top