Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Does 2 error handlers mess up excel?

I have this bit of code:
RETRY1:
Windows(NameWorksheet & ".xls").Activate
On Error GoTo ERRORTRAP1:
Sheets("Estimated - BA Approved").Select
Columns("A:A").Select
Dim T1
T1 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T1).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Sheets("NOT Estimated - BA NOT Approved").Select
Columns("A:A").Select
Dim T2
T2 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T2).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

RETRY2:
Windows(OldWorksheet & ".xls").Activate
On Error GoTo ErrHandler:



And then later on I have this bit of code:
Exit Sub
Else
End If
Next j
Next i
STOP2:
MsgBox ("This program has run and found no matching project numbers. You
may now combine Demand data.")
End Sub
ERRORTRAP1:
NameWorksheet = InputBox("You have entered an incorrect name of the new
Demand worksheet. Please try again.")
Resume RETRY1
ERRHANDLER:
OldWorksheet = InputBox("You have entered an incorrect old Demand worksheet
name. Please try again.")
Resume RETRY2:


Can Excel not handle two error handling statements? Does the "seek until
you find: ERRHANDLER" not work if you have already searched for a different
goto line? What's the deal?

Thanks,
Nicole
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Does 2 error handlers mess up excel?

Nope. VBA is able to handle multiple error handlers. It is very difficult
from your code to determine just what is causing the errors, but from what I
can tell you might be overusing the errorhandler (see my little rant at the
bottom of this post). You can not use an error handler within another error
handler, which I think is what is happening to you. Your code throws an error
which send you to the error handler. Within that code you are trying to react
to an error generated within the error handler itself which is not allowed.

IMO errorhandling is only to be used as a last resort to allow your code to
react to rare or unforseeable events. In short if you can reasonably forsee a
problem your code should handle that in the regular flow and not through an
error handler. A legitimate error to catch would be one like trying to access
a file on the network, but the network is down, or trying to read from a file
but somehow the file was moved. These are thing you can not reasonably
forsee, so an error handler is a great way to deal with them. Part of my
reasoning for this is once in the error handler, if an error is thrown, there
is not much you can do.
--
HTH...

Jim Thomlinson


"Nicole Seibert" wrote:

I have this bit of code:
RETRY1:
Windows(NameWorksheet & ".xls").Activate
On Error GoTo ERRORTRAP1:
Sheets("Estimated - BA Approved").Select
Columns("A:A").Select
Dim T1
T1 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T1).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Sheets("NOT Estimated - BA NOT Approved").Select
Columns("A:A").Select
Dim T2
T2 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T2).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

RETRY2:
Windows(OldWorksheet & ".xls").Activate
On Error GoTo ErrHandler:



And then later on I have this bit of code:
Exit Sub
Else
End If
Next j
Next i
STOP2:
MsgBox ("This program has run and found no matching project numbers. You
may now combine Demand data.")
End Sub
ERRORTRAP1:
NameWorksheet = InputBox("You have entered an incorrect name of the new
Demand worksheet. Please try again.")
Resume RETRY1
ERRHANDLER:
OldWorksheet = InputBox("You have entered an incorrect old Demand worksheet
name. Please try again.")
Resume RETRY2:


Can Excel not handle two error handling statements? Does the "seek until
you find: ERRHANDLER" not work if you have already searched for a different
goto line? What's the deal?

Thanks,
Nicole

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default Does 2 error handlers mess up excel?

I believe before label ERRORTRAP1: it should be Exit Sub not End Sub.

As it is it should not compile since the label is outside of sub.

And End Sub should be after Resume RETRY2.



*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Does 2 error handlers mess up excel?

Thanks for the help.
In this case I am asking the user to input workbook names (this is near the
beginning of my code) and if they type these in incorrectly I want some way
to catch this error and give them a chance to retype the workbook name. This
has not worked so far.

"Jim Thomlinson" wrote:

Nope. VBA is able to handle multiple error handlers. It is very difficult
from your code to determine just what is causing the errors, but from what I
can tell you might be overusing the errorhandler (see my little rant at the
bottom of this post). You can not use an error handler within another error
handler, which I think is what is happening to you. Your code throws an error
which send you to the error handler. Within that code you are trying to react
to an error generated within the error handler itself which is not allowed.

IMO errorhandling is only to be used as a last resort to allow your code to
react to rare or unforseeable events. In short if you can reasonably forsee a
problem your code should handle that in the regular flow and not through an
error handler. A legitimate error to catch would be one like trying to access
a file on the network, but the network is down, or trying to read from a file
but somehow the file was moved. These are thing you can not reasonably
forsee, so an error handler is a great way to deal with them. Part of my
reasoning for this is once in the error handler, if an error is thrown, there
is not much you can do.
--
HTH...

Jim Thomlinson


"Nicole Seibert" wrote:

I have this bit of code:
RETRY1:
Windows(NameWorksheet & ".xls").Activate
On Error GoTo ERRORTRAP1:
Sheets("Estimated - BA Approved").Select
Columns("A:A").Select
Dim T1
T1 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T1).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Sheets("NOT Estimated - BA NOT Approved").Select
Columns("A:A").Select
Dim T2
T2 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T2).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

RETRY2:
Windows(OldWorksheet & ".xls").Activate
On Error GoTo ErrHandler:



And then later on I have this bit of code:
Exit Sub
Else
End If
Next j
Next i
STOP2:
MsgBox ("This program has run and found no matching project numbers. You
may now combine Demand data.")
End Sub
ERRORTRAP1:
NameWorksheet = InputBox("You have entered an incorrect name of the new
Demand worksheet. Please try again.")
Resume RETRY1
ERRHANDLER:
OldWorksheet = InputBox("You have entered an incorrect old Demand worksheet
name. Please try again.")
Resume RETRY2:


Can Excel not handle two error handling statements? Does the "seek until
you find: ERRHANDLER" not work if you have already searched for a different
goto line? What's the deal?

Thanks,
Nicole

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Does 2 error handlers mess up excel?

Give something similar to this a try...

dim wbk as workbook

on error resume next
set wbk = Windows(NameWorksheet & ".xls")
do while wbk is nothing
'reprompt for workbook
NameWorksheet = inputbox("Enter the name")
set wbk = Windows(NameWorksheet & ".xls")
loop
on error goto 0
wbk.activate

--
HTH...

Jim Thomlinson


"Nicole Seibert" wrote:

Thanks for the help.
In this case I am asking the user to input workbook names (this is near the
beginning of my code) and if they type these in incorrectly I want some way
to catch this error and give them a chance to retype the workbook name. This
has not worked so far.

"Jim Thomlinson" wrote:

Nope. VBA is able to handle multiple error handlers. It is very difficult
from your code to determine just what is causing the errors, but from what I
can tell you might be overusing the errorhandler (see my little rant at the
bottom of this post). You can not use an error handler within another error
handler, which I think is what is happening to you. Your code throws an error
which send you to the error handler. Within that code you are trying to react
to an error generated within the error handler itself which is not allowed.

IMO errorhandling is only to be used as a last resort to allow your code to
react to rare or unforseeable events. In short if you can reasonably forsee a
problem your code should handle that in the regular flow and not through an
error handler. A legitimate error to catch would be one like trying to access
a file on the network, but the network is down, or trying to read from a file
but somehow the file was moved. These are thing you can not reasonably
forsee, so an error handler is a great way to deal with them. Part of my
reasoning for this is once in the error handler, if an error is thrown, there
is not much you can do.
--
HTH...

Jim Thomlinson


"Nicole Seibert" wrote:

I have this bit of code:
RETRY1:
Windows(NameWorksheet & ".xls").Activate
On Error GoTo ERRORTRAP1:
Sheets("Estimated - BA Approved").Select
Columns("A:A").Select
Dim T1
T1 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T1).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

Sheets("NOT Estimated - BA NOT Approved").Select
Columns("A:A").Select
Dim T2
T2 = Cells(Rows.Count, 1).End(xlUp).Row
Range("A2:R" & T2).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

RETRY2:
Windows(OldWorksheet & ".xls").Activate
On Error GoTo ErrHandler:



And then later on I have this bit of code:
Exit Sub
Else
End If
Next j
Next i
STOP2:
MsgBox ("This program has run and found no matching project numbers. You
may now combine Demand data.")
End Sub
ERRORTRAP1:
NameWorksheet = InputBox("You have entered an incorrect name of the new
Demand worksheet. Please try again.")
Resume RETRY1
ERRHANDLER:
OldWorksheet = InputBox("You have entered an incorrect old Demand worksheet
name. Please try again.")
Resume RETRY2:


Can Excel not handle two error handling statements? Does the "seek until
you find: ERRHANDLER" not work if you have already searched for a different
goto line? What's the deal?

Thanks,
Nicole

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel displays mess after input - OK after just a zoom????? Leon[_2_] Excel Discussion (Misc queries) 0 October 30th 09 02:37 PM
Quickbooks exports to Excel, cleaning up the mess afterwards Mick Warren, TechniCater Excel Worksheet Functions 1 April 25th 06 07:15 PM
i installed outlook and getting an error mess of cant connect???? Mrs. I have NO IDEA what I am Doing!!! New Users to Excel 1 November 3rd 05 01:22 AM
Error Handlers JohnUK Excel Programming 2 September 5th 05 06:27 PM
Fonts missing from latest Excel mess up my files. Paul Brown Excel Programming 3 January 20th 05 06:24 PM


All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"