Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default 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!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default 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!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default 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!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Statement to give focus to a specific control on a UserForm? Fred Holmes Excel Programming 3 December 20th 04 07:56 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM
Linking userform to userform in Excel 2003 missmelis01 Excel Programming 2 August 27th 04 08:07 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"