Various IF statements - VBA

Fmeister

Registered User.
Local time
Today, 19:00
Joined
Dec 21, 2010
Messages
45
Hi, I am trying to get the code below to work in excel macro userform.

If OptbtnSalesComms Then
If txtPandL.Text <= 0 Then
txtanalysis.Text = "No Sales Commission"
If txtPandL.Text >= 0 Then
txtanalysis.Text = "Sales Commission =" & " " & "£" & txtPandL.Text * 0.1

ElseIf OptbtnFin Then
If txtPandL.Text <= 0 Then
txtanalysis.Text = "Made a Loss, Notify Line Manager to review"
If txtPandL.Text <= 200 Then
txtanalysis.Text = "Not a Huge Profit, Notify Line Manager to review"
If txtPandL.Text >= 200 Then
txtanalysis.Text = "Substantial profit today, Well Done!!!"

ElseIf OptbtnVAT Then
If txtPandL.Text <= 0 Then
txtanalysis.Text = "No VAT Payable"
If txtPandL.Text >= 0 Then
txtanalysis.Text = "VAT =" & " " & "£" & txtPandL.Text * 0.175

Elsetxt.analysis.Text = "please select 'Type of Analysis'"

End If



Can somebody please tell me where I am going wrong
 
What you have written is a mess; for each and every IF there needs to be an End If.

Have you come across Select Case - that may help.

Also code lines like If OptbtnSalesComms Then will not work as OptbtnSalesComms needs to equal something; such as the other lines in your code

If txtPandL.Text <= 0 Then

Compound IF statements are not always good practice. I suggest you get each If Statement loop working properly than (if you must) compound them together afterwards.

Bear in mind IF statements can work with the keyword OR and AND

More work requires I am afraid.
 
What you have written is a mess; for each and every IF there needs to be an End If.

Have you come across Select Case - that may help.

Also code lines like If OptbtnSalesComms Then will not work as OptbtnSalesComms needs to equal something; such as the other lines in your code

If txtPandL.Text <= 0 Then

Compound IF statements are not always good practice. I suggest you get each If Statement loop working properly than (if you must) compound them together afterwards.

Bear in mind IF statements can work with the keyword OR and AND

More work requires I am afraid.


Ok Got it to work and thanks for your review:::::::

Private Sub btnAnalysis_Click()

If OptbtnSalesComms Then

If txtPandL.Text <= 0 Then
txtAnalysis.Text = "No Sales Commission"

ElseIf txtPandL.Text >= 0 Then

txtAnalysis.Text = "Sales Commission =" & " " & "£" & txtPandL.Text * 0.1

End If



ElseIf OptbtnFin Then

If txtPandL.Text <= 0 Then

txtAnalysis.Text = "Made a Loss, Notify Line Manager to review"

ElseIf txtPandL.Text <= 200 Then

txtAnalysis.Text = "Not a Huge Profit, Notify Line Manager to review"

ElseIf txtPandL.Text >= 200 Then

txtAnalysis.Text = "Substantial profit today, Well Done!!!"

End If

ElseIf OptbtnVAT Then

If txtPandL.Text <= 0 Then

txtAnalysis.Text = "No VAT Payable"

ElseIf txtPandL.Text >= 0 Then

txtAnalysis.Text = "VAT =" & " " & "£" & txtPandL.Text * 0.175

End If

Else: txtAnalysis.Text = "Please select 'Type of Analysis'"

End If


End Sub
 

Users who are viewing this thread

Back
Top Bottom