If, ElseIf, Else Statements with Multiple Conditions

torminator111

New Member
Joined
Jul 16, 2014
Messages
2
Hi All!

I have been experiencing this issue in a few macros I've created and don't understand what is wrong with any of the syntax structures I've been experimenting with. When I run the code, it doesn't compile and gives me a message that says "Else without If." From online research, it seems that the syntax is correct. Any ideas?

Structure 1 (If, ElseIf, Else:):
If vara = "NA" Or varb = "W" GoTo Proceed
ElseIf varx = "" Or vary = "" Or varz = "" _
Then MsgBox "Main Information missing, please check Main entries", vbExclamation: GoTo Suspend
Else: GoTo Suspend
End If

Structure 2 (nested Ifs):


If varx = "" Or vary = "" Or varz = "" Then
If vara = "NA" Or varb = "W" GoTo Proceed
Else: MsgBox "Main Information missing, please check Main entries", vbExclamation: GoTo Suspend
End If
Else: GoTo Proceed
End If

Structure 3 (complex If conditions):
If (vara = "NA" Or varb="W") And (varx="" Or vary="" Or varz="") GoTo Proceed
Else: MsgBox "Main Information missing, please check Main entries", vbExclamation: GoTo Suspend
End If


Thank you SO MUCH in advance for your help!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
You are using elseif as if it were self closing. It isnt. Think of it this way...

Code:
If vara = "NA" Or varb = "W" 
        GoTo Proceed
Else
        If varx = "" Or vary = "" Or varz = "" Then 
              MsgBox "Main Information missing, please check Main entries", vbExclamation
              GoTo Suspend
        Else
             GoTo Suspend
        End if
End If
 
Last edited:
Upvote 0
Hmm. That makes sense. I am, however, still unable to compile the code (with the error message "Else without If"). Could this be something with my computer?
 
Upvote 0

Forum statistics

Threads
1,215,455
Messages
6,124,937
Members
449,196
Latest member
Maxkapoor

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