Compile Error

G

Guest

The following macro is triggering a "Block If Without End If" compile error
when invoked, but the necessary End If seems to be there.

Thanks for any assistance.

Sub ToggleNotes()
' Toggles visibility of Notes worksheet; inserts if not yet inserted
' If on the master Macros sheet, toggles visibility of the MenuSheet
' Ctrl-n

Dim intSheet As Integer
On Error GoTo ErrHandler

If ActiveWorkbook.Name = "Macros.xls" Then
With Sheets("MenuSheet")
.Visible = Not Sheets("MenuSheet").Visible
.Activate
End With
Else

' If Notes sheet doesn't exist, add, else toggle visibility and
activate
If Not SheetExists("Notes") Then
Sheets.Add
Type:="\\Diamond\Departments\Cost_Estimating\Templates\Notes.xlt"
ActiveWorkbook.Sheets("Notes").Move _
After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)

Else

Application.ScreenUpdating = False
With Sheets("Notes")
.Visible = Not Sheets("Notes").Visible
.Activate
End With

End If

If Sheets("Notes").Visible = False Then

'If multi-page, select page to return to, otherwise return to
Sheet1
If ActiveWorkbook.Sheets.Count > 2 Then
intSheet = InputBox("Enter sheet number to return to:",
"Sheet Number", 2)
Sheets(intSheet).Activate
Else
Sheets(1).Activate
End If

Application.ScreenUpdating = True

End If

ErrExit:
Exit Sub

ErrHandler:
MsgBox "There has been the following error. Please contact the macro
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & " " & Err.Description
Resume ErrExit

End Sub
 
G

Guest

Need End If after
If ActiveWorkbook.Sheets.Count > 2 Then
intSheet = InputBox("Enter sheet number to return to:",
"Sheet Number", 2)
 
C

Chip Pearson

You're missing an End If to sync up with

If ActiveWorkbook.Sheets.Count > 2 Then


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top