Multiple On Error Statements
Contents |
Error GoTo commands, but If one error appear the next error results in Run-time error 91. Do I have to rese something after each check
On Error Resume Next
(...and in case, what?)? Thanks, Erlend Dim test1, test2, test3 Sub checkk() test1 = False test2 = False test3 = False check1: On Error GoTo check2 Columns("B").Find(What:="length").Activate test1 = True check2: On Error GoTo check3 tab1start = Columns("A").Find(What:="md").Row test2 = True check3: On Error GoTo stopp tab2start = Columns("B").Find(What:="east").Row test3 = True stopp: If Not test3 Then MsgBox "Unknown format" Exit Sub End If End Su -- Message posted http://www.ibm.com/support/knowledgecenter/SSVRGU_9.0.0/com.ibm.designer.domino.main.doc/LSAZ_MULTIPLE_ON_ERROR_STATEMENTS.html from http://www.ExcelForum.com e18, Apr 13, 2004 #1 Advertisements e18 Guest ...I have tried with *Err.Clear* with no luc -- Message posted from http://www.ExcelForum.com e18, Apr 13, 2004 #2 Advertisements e18 Guest I could of course use *On Error Resume Next* (tab1start and tab2star are equal to zero if Columns.Find not found) as a workaround, but still would very much like an answer to how to have http://www.pcreview.co.uk/threads/on-error-goto-how-to-use-multiple.974111/ more than one *O Error GoTo* in a macro. Thank you. Erlen -- Message posted from http://www.ExcelForum.com e18, Apr 13, 2004 #3 Tom Ogilvy Guest Dim rng1 as Range, rng2 as Range set rng1 = Columns(1).Find("Start") set rng2 = Columns(1).Find("End") if not rng1 is nothing then msgbox "Start at " & rng1.row End if if not rng2 is nothing then msgbox "End at " & rng2.row End if This doesn't raise an error if the search term isn't found. -- Regards, Tom Ogilvy "e18 >" <<> wrote in message news:... > I could of course use *On Error Resume Next* (tab1start and tab2start > are equal to zero if Columns.Find not found) as a workaround, but I > still would very much like an answer to how to have more than one *On > Error GoTo* in a macro. > > Thank you. > > Erlend > > > --- > Message posted from http://www.ExcelForum.com/ > Tom Ogilvy, Apr 13, 2004 #4 Alan Beban Guest Tom Ogilvy provided some code to avoid your problem. Nevertheless, I have inserted some code in your originally provided code to illustrate one way to have multiple On Error statements executed. You need to resume execution (i.
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us http://stackoverflow.com/questions/7289220/the-second-of-2-on-error-goto-statements-gets-ignored Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up The second of 2 'On Error goto ' statements on error gets ignored up vote 2 down vote favorite I have some code that tries to set 11x17 paper as a default... On Error GoTo PageSizeErr ActiveSheet.PageSetup.PaperSize = xlPaperTabloid ' more code here PageSizeErr: On Error GoTo PageErr2 ActiveSheet.PageSetup.PaperSize = xlPaper11x17 'try another 11x17 driver definition GoTo resumePrinting PageErr2: MsgBox ("There's a problem setting Tabloid paper for the printer you have selected." & Chr(10) _ & "If you on error goto have an 11x17 printer selected, please contact EMBC, otherwise, try a different printer.") Exit Sub -------------- end of code sample ----------------- When it gets to the second 'ActivateSheet.PageSetup... line, instead of going to PageErr2 lable I get an error dialog box. (I have a printer selected that doesn't support 11x17 which is what I'm trying to test for.) The multiple error handlers are needed as it seems that different printer drivers handle the setting the differently. Why doesn't the second 'On Error goto ' statement get recognized? excel-vba share|improve this question edited Sep 2 '11 at 21:15 Mike Sherrill 'Cat Recall' 54.2k755102 asked Sep 2 '11 at 21:06 Greg 1112 1 Just change your second "on error goto" to a goto and you're done. –Kevin Sep 2 '11 at 21:27 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote You can't use on error goto within an error handler. See http://www.cpearson.com/excel/errorhandling.htm Maybe try something like this: Sub Tester() Dim pSize As XlPaperSize pSize = xlPaperTabloid On Error GoTo haveError: ActiveSheet.PageSetup.PaperSize = pSize 'print stuff... Exit Sub haveveError: If pSize = xlPaperTabloid Then pSize = xlPaper11x17 Resume End If MsgBox ("Couldn't print using tabloid or 11x17