ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Compile Error (https://www.excelbanter.com/excel-programming/367551-compile-error.html)

Sprinks

Compile Error
 
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\Templ ates\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

Charlie

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


"Sprinks" wrote:

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\Templ ates\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


Chip Pearson

Compile Error
 
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



"Sprinks" wrote in message
...
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\Templ ates\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




Sprinks

Compile Error
 
Thanks, Charlie and Chip.


All times are GMT +1. The time now is 03:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com