VBA IF Statements: Can you have multiple actions in the "Then" area?

clawlan

Board Regular
Joined
Aug 9, 2010
Messages
62
I can't figure out how to have multiple actions occur in the "Then" area of a VBA IF statement. I am trying to set 2 different variables based on the result of an if statement:

If var1 = apple then
var2 = 0 AND var3 = 1
elseif...
...
endif

What am I missing? :confused:
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hello, maybe something like:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> example()<br><br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">True</SPAN> = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        var1 = 1<br>        var2 = 2<br>    <SPAN style="color:#00007F">Else</SPAN><br>        <br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Your welcome, You can do many actions within the If statement. In other words you may have multiple lines of code doing different things for the THEN and/or ELSE portions of the IF. It is not limited to only one action.
 
Upvote 0

Forum statistics

Threads
1,222,622
Messages
6,167,138
Members
452,098
Latest member
xel003

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