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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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