Hi All,
I am trying to set a vba code to revert to a single layout when closing a workbook. I have the code below, however it is returnng a compile error: "Block If without End If" on the last End If row (I have bold the row).
I dont pretend to be amazing at VBA but I know my way around some basic code, but can someone please explain why I am getting this error and how to avoid it in future?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim answer As String
Dim question As String
question = "Are you sure?"
answer = Msgbox(question, vbYesNo, "Message")
If answer = vbNo Then
Cancel = True
Exit Sub
Else
Worksheets("Dashboard").Visible = True
Worksheets("Part Time Calculations").Visible = True
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Dashboard" And ws.Name <> "Part Time Calculations" Then
ws.Visible = False
End If
End If
Next
Worksheets("Dashboard").Activate
ActiveWorkbook.Save
End Sub
Bookmarks