Nested If Then ElseIF keeps returning Compile Error

Vanish29

New Member
Joined
Apr 28, 2016
Messages
26
Hello,
I am attempting to automate Custom Views on a form.

VBA Code:
Sub CustomViews()
'
' Designed to make the custom views automated
'
If Sh1.Range("G4") = "All Products + Metered" Then ActiveWorkbook.CustomViews("All Products + Metered").Show
ElseIf Sh1.Range("G4") = "All Products Non-Metered" Then ActiveWorkbook.CustomViews("All Products Non-Metered").Show
ElseIf Sh1.Range("G4") = "Bill Pay + S2" Then ActiveWorkbook.CustomViews("Bill Pay + S2").Show
ElseIf Sh1.Range("G4") = "Bill Pay Only" Then ActiveWorkbook.CustomViews("Bill Pay Only").Show
ElseIf Sh1.Range("G4") = "Billing + Submetered" Then ActiveWorkbook.CustomViews("Billing + Submetered").Show
ElseIf Sh1.Range("G4") = "Billing Non Submetered" Then ActiveWorkbook.CustomViews("Billing Non Submetered").Show
ElseIf Sh1.Range("G4") = "Billing + Submetered & Bill Pay" Then ActiveWorkbook.CustomViews("Billing + Submetered").Show
ElseIf Sh1.Range("G4") = "Billing + Non Submetered & Bill Pay" Then ActiveWorkbook.CustomViews("Billing Non Submetered").Show
Else: ActiveWorkbook.CustomViews("All Products + Metered").Show
End If
'
End Sub
Everytime I run it, I get Compile Error: Else without If, but I cannot seem to find the issue.
My first guess was that the issue was the indentation. I tried using Smart Indenter but it still produces the same error.
I am completely uncertain how to proceed and searching forums has not produced useful guidance.
 
For the purpose of this question, here is the correct answer, provided by 6StringJazzer, with the necessary modifications for Explicit Code
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,221,522
Messages
6,160,308
Members
451,637
Latest member
hvp2262

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