On Error GoTo Issue, please help!

  • Beginner here! I have this code where it tries to find a certain criteria, but if it doesn't find it I want it to loop back to the beginning and try another criteria. My issue is after it fails once, the On Error GoTo will not work again since it's already on a hard fail (atleast from what I've read). Is there any way to make it loop even if it's already failed once? Also note that if it does pass(IE find the creteria, it goes through a whole process and then loops back to the start hence the Do right after ErrHandler) Below is the code


  • Re: On Error GoTo Issue, please help!


    Quote from norie;624707

    Do you have a list of criteria you want to go through?



    Bascially what I do is have a list of names in B that I paste in so think


    Henry
    Mark
    John
    ashley
    jim
    juan


    and sometimes jim will show up and other times his name won't.

  • Re: On Error GoTo Issue, please help!


    Just some comments without seeing all your code - you didn't post it alL!


    Rather than trying to activate a range directly in the .FIND, assign the results of the FIND to a range variable. You can then check if that range is nothing (in other words, the search term was not found), or not (term found)


    For example



    Considering your code, above, you should also read up on error handling, can't imagine why you have 2 On Error statements pointing to the same error handler... I might suggest this as a starting point.

  • Re: On Error GoTo Issue, please help!


    You don't need to slect the ranges or sheets.


    Code
    On Error Goto ErrHandler 
        Selection.Find(What:=ErrorCode, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
        False, SearchFormat:=False).Activate 
        On Error Goto ErrHandler


    If you really want to go use an error handler like this then the second on error should release error handling back to Excel


    Cytop's suggestion is the way to go.


    Code
    On Error Goto ErrHandler 
        Selection.Find(What:=ErrorCode, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ 
        False, SearchFormat:=False).Activate 
        On Error Goto 0
  • Re: On Error GoTo Issue, please help!


    Hi,


    You've already had some feedback regarding the general structure of your code so I'll just comment on the error-handling part.


    When an error arises it effectively flips a switch so that error mode is 'on'. Whilst in error mode any subsequent errors will not be handled (which is what you were experiencing). The way to switch it 'off' again lies in the use of Resume (or exiting the sub). It's also good practice to have your error-handling routines at the end of a sub.


    Compare the following:


  • Re: On Error GoTo Issue, please help!


    Perhaps something like this.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!