ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple commands from single IF. (https://www.excelbanter.com/excel-programming/287312-multiple-commands-single-if.html)

beeawwb[_3_]

Multiple commands from single IF.
 
Now, I know if I write some functions then this will be alot easier, bu
I want to do some IF's that run multiple commands. It should be quit
easy, but I don't know what Excel wants.

Here's an example of how I "think" it, when I'm doing this in my head.

IF (Condition = True)
Then
{
Command1
Command2
Command3
}
Else
{
Command4
Command5
}


I suppose the function way to do it would be

If (Condition = True) Then Truestuff() Else Falsestuff()

With
Sub Truestuff()
Command1
Command2
Command3
End Sub

Sub Falsestuff()
Command4
Command5
End Sub

That's the other way I can do it. Is there any way to nest multipl
commands in a single If Then Else set?

Hope that makes sense, Thanks for the help.

-Bo

--
Message posted from http://www.ExcelForum.com


Doug Glancy[_6_]

Multiple commands from single IF.
 
If all you're looking for is the syntax, here's an example. You can include
as many commands as you want between the Ifs, Elses, ElseIfs and EndIfs:

If var1 var2 then
var1 = 0
msgbox var2
Elseif var1<var2
var2 = 0
msgbox var1
Else
msgbox "the 2 variables are equal"
EndIf

hth,

Doug

"beeawwb " wrote in message
...
Now, I know if I write some functions then this will be alot easier, but
I want to do some IF's that run multiple commands. It should be quite
easy, but I don't know what Excel wants.

Here's an example of how I "think" it, when I'm doing this in my head.

IF (Condition = True)
Then
{
Command1
Command2
Command3
}
Else
{
Command4
Command5
}


I suppose the function way to do it would be

If (Condition = True) Then Truestuff() Else Falsestuff()

With
Sub Truestuff()
Command1
Command2
Command3
End Sub

Sub Falsestuff()
Command4
Command5
End Sub

That's the other way I can do it. Is there any way to nest multiple
commands in a single If Then Else set?

Hope that makes sense, Thanks for the help.

-Bob


---
Message posted from http://www.ExcelForum.com/




beeawwb[_4_]

Multiple commands from single IF.
 
So, just to double check (I only just saw this reply)

The syntax is.

If (Condition) Then [ENTER]
Command
Command
Command
ELSEIF (condition2) Then [ENTER]
Command
ELSE [ENTER]
Command
ENDIF

So, what I'm doing as I see it, just to double-check-reiterate,

If = {
Lots of stuff = Commands
EndIf = }

Thanks for the help, I'll try it out soon.

-Bob


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 12:53 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com