On Error Goto ignored

  • Thread starter Thread starter Fred Smith
  • Start date Start date
F

Fred Smith

I wanted to determine whether a sheet existed in the active workbook. So I
used:

On Error Goto NoPerfSheet
Sheets("Performance").Select
On Error Goto 0

However, Excel always stopped at the Sheets command, with a Subscript out of
range error.

I knew there would never be more than two sheets in the workbook, so I got
it working by using:

IF Sheets.Count = 1 Goto NoPerfSheet

However, I'm why the On Error statement was ignored.

What conditions causes VBE to ignore On Error?
 
Fred,

something like this

Function SheetExists(strName As String) As Boolean
Dim shName As Worksheet
On Error Resume Next
Set shName = Sheets(strName)
On Error GoTo 0
SheetExists = Not shName Is Nothing
End Function

Robin Hammond
www.enhanceddatasystems.com
 
That's a workaround I hadn't thought of, and I could see using it sometime.
Buy why was my On Error Goto ignored?
 
Fred,

Your code runs as it should on my XL2002.

On Error GoTo NoPerfSheet
Sheets("Performance").Select
On Error GoTo 0
Exit Sub
NoPerfSheet:
MsgBox "NoPerfSheet"
 

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

Back
Top