![]() |
If Then statement in a userform sub
Hi all:
The following sub is for the "OK" button on the userform. Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 JOIST.Hide End Sub The problem is when the first "IF" statement is not true it does not skip "Call Analyze" which is a sub in the standard module. how can i make it,when the first "if" statement is not true, to go to the second "if" statement? Thanks for any help! |
If Then statement in a userform sub
Sam,
Either: Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze End If If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 End If JOIST.Hide End Sub OR: Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze ElseIf OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 End If JOIST.Hide End Sub It's not clear what to do if OptionSelect and OptionALL are both False. HTH, Bernie MS Excel MVP wrote in message oups.com... Hi all: The following sub is for the "OK" button on the userform. Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 JOIST.Hide End Sub The problem is when the first "IF" statement is not true it does not skip "Call Analyze" which is a sub in the standard module. how can i make it,when the first "if" statement is not true, to go to the second "if" statement? Thanks for any help! |
If Then statement in a userform sub
Sam,
These two will operate in sequentially If Condition Then Statement 'only if true Statement 'regardless of condition These two will only happen if the Condition is true If Condition Then Statement1 Statement2 End If These will operate exclusively If Condition Then Statement1 Statement2 ElseIf Condition2 then Statement3 Statement4 Else Statement5 End If It looks like you need the last of these If OptionALL Then Cells(1, 2).Value = "ALL" Analyze ElseIf OptionSelect Then Cells(1, 2).Value = TextBox1.Text Analyze2 End If JOIST.Hide End Sub -- Robin Hammond www.enhanceddatasystems.com wrote in message oups.com... Hi all: The following sub is for the "OK" button on the userform. Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 JOIST.Hide End Sub The problem is when the first "IF" statement is not true it does not skip "Call Analyze" which is a sub in the standard module. how can i make it,when the first "if" statement is not true, to go to the second "if" statement? Thanks for any help! |
If Then statement in a userform sub
Not sure how exactly you want it, but I think this is it:
Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze Else If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 JOIST.Hide End If End If End Sub Maybe you can leave If OptionSelect Then and the corresponding If out. RBS wrote in message oups.com... Hi all: The following sub is for the "OK" button on the userform. Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 JOIST.Hide End Sub The problem is when the first "IF" statement is not true it does not skip "Call Analyze" which is a sub in the standard module. how can i make it,when the first "if" statement is not true, to go to the second "if" statement? Thanks for any help! |
If Then statement in a userform sub
Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze ElseIf OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 End If JOIST.Hide End Sub -- HTH RP (remove nothere from the email address if mailing direct) wrote in message oups.com... Hi all: The following sub is for the "OK" button on the userform. Private Sub CommandButton1_Click() If OptionALL Then Cells(1, 2).Value = "ALL" Call Analyze If OptionSelect Then Cells(1, 2).Value = TextBox1.Text Call Analyze2 JOIST.Hide End Sub The problem is when the first "IF" statement is not true it does not skip "Call Analyze" which is a sub in the standard module. how can i make it,when the first "if" statement is not true, to go to the second "if" statement? Thanks for any help! |
If Then statement in a userform sub
Bernie,Robin,RB,and Bob:
Thank you all so much, not only for answering my question, but also for taking the time to teach me the proper way of structuring the "if Then" statement. |
All times are GMT +1. The time now is 07:27 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com