Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Business Applications
Tag Cloud
access acer asus bios bsod crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop mac malware memory monitor motherboard network operating system printer problem ram registry router security slow software sound svchost.exe trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Business Applications >
Solved: Excel vb error trapping problem

Reply  
Thread Tools
davodave's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2008
Experience: Intermediate
29-Mar-2009, 10:46 PM #1
Solved: Excel vb error trapping problem
I have a large excel VB macro which relys on error trapping to move on when it encounters an error.
I find that if I have more that one "on error goto [Line]" statement in a procedure, it only uses the first one. What do I have to do to switch to the next error handler?
Here is an example:

SKILL_CALLS:
Sheets("Skillset").Select
Range("A1").Select
For counter = 1 To 15
Cells.Find(What:="-", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Selection.EntireRow.Insert
Selection.Offset(1, 0).Select
Next counter

Range("A4").Select
For counter = 1 To 15
On Error GoTo LAST_SORT
Range(ActiveCell, ActiveCell.CurrentRegion).Select
Selection.Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Next counter
LAST_SORT:
Range("A3").Select
For counter = 1 To 15
On Error GoTo ENDOF
If ActiveCell = "Bookings_sk" Then Selection.Offset(1, 0).Select Else GoSub BOOKINGS_IN
If ActiveCell = "Campaign_sk" Then Selection.Offset(1, 0).Select Else GoSub CAMPAIGN_IN
If ActiveCell = "General_sk" Then Selection.Offset(1, 0).Select Else GoSub GENERAL_IN
If ActiveCell = "Patonga_sk" Then Selection.Offset(1, 0).Select Else GoSub PATONGA_IN
If ActiveCell = "Planning_sk" Then Selection.Offset(1, 0).Select Else GoSub PLANNING_IN
If ActiveCell = "Rates_sk" Then Selection.Offset(1, 0).Select Else GoSub RATES_IN
If ActiveCell = "VIP_sk" Then Selection.Offset(1, 0).Select Else GoSub VIP_IN
If ActiveCell = "Water_Sewer_sk" Then Selection.Offset(1, 0).Select Else GoSub WATER_SEWER_IN
Selection.End(xlDown).Select
Selection.Offset(1, 0).Select
Next counter
BOOKINGS_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "Bookings_sk"
Selection.Offset(1, 0).Select
Return
CAMPAIGN_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "Campaign_sk"
Selection.Offset(1, 0).Select
Return

GENERAL_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "General_sk"
Selection.Offset(1, 0).Select
Return
PATONGA_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "Patonga_sk"
Selection.Offset(1, 0).Select
Return
PLANNING_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "Planning_sk"
Selection.Offset(1, 0).Select
Return
RATES_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "Rates_sk"
Selection.Offset(1, 0).Select
Return
VIP_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "VIP_sk"
Selection.Offset(1, 0).Select
Return
WATER_SEWER_IN:
Selection.EntireRow.Insert
ActiveCell.FormulaR1C1 = "Water_sewer_sk"
Selection.Offset(1, 0).Select
Return
ENDOF:
Range("A1").Select
'This locates the first agent by finding GENERAL_SK.
On Error GoTo CALL_LAST_TAB
Cells.Find(What:="General_sk", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Replace What:="General_sk", Replacement:="General Skill", _
LookAt:=xlPart, SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat _
:=False, ReplaceFormat:=False
Range(ActiveCell, ActiveCell.CurrentRegion).Select
Fluffmatic's Avatar
Member with 116 posts.
 
Join Date: Mar 2009
Experience: Seeking Enlightenment
30-Mar-2009, 07:46 AM #2
You need to do a call to "err.clear" in your error handler to reset this after its called.
davodave's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2008
Experience: Intermediate
30-Mar-2009, 11:37 PM #3
Works a treat. Thanks
davodave's Avatar
Junior Member with 3 posts.
 
Join Date: Nov 2008
Experience: Intermediate
30-Mar-2009, 11:38 PM #4
Works a treat, thanks.
MRdNk's Avatar
Computer Specs
Member with 439 posts.
 
Join Date: Apr 2007
Location: UK
Experience: Damn I'm good!
31-Mar-2009, 04:19 AM #5
Please mark as solved, at the top.
Reply

Tags
error trapping, excel, visual basic

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 02:38 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.