+ Reply to Thread
Results 1 to 10 of 10

on error resume next

  1. #1
    filo666
    Guest

    on error resume next

    Hi a very easy one:

    sub gtt()
    for a=1 to 10
    cell(a,1)=cell(a,1)+cell(a,2)
    cell(c,5)="Hola" ' if the line below is error DON'T go here
    msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    next 'if error goto this next
    end sub

    I want that if an error happens goto the "next" line, and not to the next
    line
    HHS
    TIA

  2. #2
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    sub gtt()
    on error goto AnError:
    for a=1 to 10
    cell(a,1)=cell(a,1)+cell(a,2)
    cell(c,5)="Hola" ' if the line below is error DON'T go here
    msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    AnError:
    next 'if error goto this next
    end sub


    on the basis that this is a limited loop it isn't too dangerous

  3. #3
    filo666
    Guest

    Re: on error resume next

    but, what happen if the error ocurres in other part of the macro different of
    the loop?????

    "tony h" wrote:

    >
    > sub gtt()
    > on error goto AnError:
    > for a=1 to 10
    > cell(a,1)=cell(a,1)+cell(a,2)
    > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > AnError:
    > next 'if error goto this next
    > end sub
    >
    >
    > on the basis that this is a limited loop it isn't too dangerous
    >
    >
    > --
    > tony h
    > ------------------------------------------------------------------------
    > tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
    > View this thread: http://www.excelforum.com/showthread...hreadid=505378
    >
    >


  4. #4
    Jim Thomlinson
    Guest

    Re: on error resume next

    I don't see anything in your code that should be causing an error, unless the
    cells don't contain numbers and you can check for that and avoid the error.
    It is good practice to use the error handler as little as possible.
    --
    HTH...

    Jim Thomlinson


    "filo666" wrote:

    > but, what happen if the error ocurres in other part of the macro different of
    > the loop?????
    >
    > "tony h" wrote:
    >
    > >
    > > sub gtt()
    > > on error goto AnError:
    > > for a=1 to 10
    > > cell(a,1)=cell(a,1)+cell(a,2)
    > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > AnError:
    > > next 'if error goto this next
    > > end sub
    > >
    > >
    > > on the basis that this is a limited loop it isn't too dangerous
    > >
    > >
    > > --
    > > tony h
    > > ------------------------------------------------------------------------
    > > tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
    > > View this thread: http://www.excelforum.com/showthread...hreadid=505378
    > >
    > >


  5. #5
    filo666
    Guest

    Re: on error resume next

    The code where I want to use what I asked is very long, I mean, I cant paste
    it here, and oviously I don't want to use the on error goto....
    I was thinking in a on error resume next but the next should mean the next
    of the for, no the next line, How to accomplish this???

    "Jim Thomlinson" wrote:

    > I don't see anything in your code that should be causing an error, unless the
    > cells don't contain numbers and you can check for that and avoid the error.
    > It is good practice to use the error handler as little as possible.
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "filo666" wrote:
    >
    > > but, what happen if the error ocurres in other part of the macro different of
    > > the loop?????
    > >
    > > "tony h" wrote:
    > >
    > > >
    > > > sub gtt()
    > > > on error goto AnError:
    > > > for a=1 to 10
    > > > cell(a,1)=cell(a,1)+cell(a,2)
    > > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > > AnError:
    > > > next 'if error goto this next
    > > > end sub
    > > >
    > > >
    > > > on the basis that this is a limited loop it isn't too dangerous
    > > >
    > > >
    > > > --
    > > > tony h
    > > > ------------------------------------------------------------------------
    > > > tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
    > > > View this thread: http://www.excelforum.com/showthread...hreadid=505378
    > > >
    > > >


  6. #6
    Jim Thomlinson
    Guest

    Re: on error resume next

    I don't see anything in your code that should be causing an error, unless the
    cells don't contain numbers and you can check for that and avoid the error.
    It is good practice to use the error handler as little as possible.
    --
    HTH...

    Jim Thomlinson


    "filo666" wrote:

    > but, what happen if the error ocurres in other part of the macro different of
    > the loop?????
    >
    > "tony h" wrote:
    >
    > >
    > > sub gtt()
    > > on error goto AnError:
    > > for a=1 to 10
    > > cell(a,1)=cell(a,1)+cell(a,2)
    > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > AnError:
    > > next 'if error goto this next
    > > end sub
    > >
    > >
    > > on the basis that this is a limited loop it isn't too dangerous
    > >
    > >
    > > --
    > > tony h
    > > ------------------------------------------------------------------------
    > > tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
    > > View this thread: http://www.excelforum.com/showthread...hreadid=505378
    > >
    > >


  7. #7
    filo666
    Guest

    Re: on error resume next

    The code where I want to use what I asked is very long, I mean, I cant paste
    it here, and oviously I don't want to use the on error goto....
    I was thinking in a on error resume next but the next should mean the next
    of the for, no the next line, How to accomplish this???

    "Jim Thomlinson" wrote:

    > I don't see anything in your code that should be causing an error, unless the
    > cells don't contain numbers and you can check for that and avoid the error.
    > It is good practice to use the error handler as little as possible.
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "filo666" wrote:
    >
    > > but, what happen if the error ocurres in other part of the macro different of
    > > the loop?????
    > >
    > > "tony h" wrote:
    > >
    > > >
    > > > sub gtt()
    > > > on error goto AnError:
    > > > for a=1 to 10
    > > > cell(a,1)=cell(a,1)+cell(a,2)
    > > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > > AnError:
    > > > next 'if error goto this next
    > > > end sub
    > > >
    > > >
    > > > on the basis that this is a limited loop it isn't too dangerous
    > > >
    > > >
    > > > --
    > > > tony h
    > > > ------------------------------------------------------------------------
    > > > tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
    > > > View this thread: http://www.excelforum.com/showthread...hreadid=505378
    > > >
    > > >


  8. #8
    Jim Thomlinson
    Guest

    Re: on error resume next

    You can essentially use Tony's code if you want. Place the on error goto
    statement just ahead of the line(s) that will generate the error and
    immediately after that put on error goto 0 which will reset the error
    handler. You can also have multiple error handling routines if you want...

    sub gtt()
    on error goto AnError:
    for a=1 to 10
    cell(a,1)=cell(a,1)+cell(a,2)
    cell(c,5)="Hola" ' if the line below is error DON'T go here
    msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    AnError:
    next 'if error goto this next
    On error goto MyError
    'More code and stuff

    Exit Sub
    MyError:
    msgbox "Whatever"
    end sub

    --
    HTH...

    Jim Thomlinson


    "filo666" wrote:

    > The code where I want to use what I asked is very long, I mean, I cant paste
    > it here, and oviously I don't want to use the on error goto....
    > I was thinking in a on error resume next but the next should mean the next
    > of the for, no the next line, How to accomplish this???
    >
    > "Jim Thomlinson" wrote:
    >
    > > I don't see anything in your code that should be causing an error, unless the
    > > cells don't contain numbers and you can check for that and avoid the error.
    > > It is good practice to use the error handler as little as possible.
    > > --
    > > HTH...
    > >
    > > Jim Thomlinson
    > >
    > >
    > > "filo666" wrote:
    > >
    > > > but, what happen if the error ocurres in other part of the macro different of
    > > > the loop?????
    > > >
    > > > "tony h" wrote:
    > > >
    > > > >
    > > > > sub gtt()
    > > > > on error goto AnError:
    > > > > for a=1 to 10
    > > > > cell(a,1)=cell(a,1)+cell(a,2)
    > > > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > > > AnError:
    > > > > next 'if error goto this next
    > > > > end sub
    > > > >
    > > > >
    > > > > on the basis that this is a limited loop it isn't too dangerous
    > > > >
    > > > >
    > > > > --
    > > > > tony h
    > > > > ------------------------------------------------------------------------
    > > > > tony h's Profile: http://www.excelforum.com/member.php...o&userid=21074
    > > > > View this thread: http://www.excelforum.com/showthread...hreadid=505378
    > > > >
    > > > >


  9. #9
    Bob Phillips
    Guest

    Re: on error resume next

    so what do you want to happen then?

    --

    HTH

    Bob Phillips

    (remove nothere from the email address if mailing direct)

    "filo666" <[email protected]> wrote in message
    news:[email protected]...
    > but, what happen if the error ocurres in other part of the macro different

    of
    > the loop?????
    >
    > "tony h" wrote:
    >
    > >
    > > sub gtt()
    > > on error goto AnError:
    > > for a=1 to 10
    > > cell(a,1)=cell(a,1)+cell(a,2)
    > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > AnError:
    > > next 'if error goto this next
    > > end sub
    > >
    > >
    > > on the basis that this is a limited loop it isn't too dangerous
    > >
    > >
    > > --
    > > tony h
    > > ------------------------------------------------------------------------
    > > tony h's Profile:

    http://www.excelforum.com/member.php...o&userid=21074
    > > View this thread:

    http://www.excelforum.com/showthread...hreadid=505378
    > >
    > >




  10. #10
    filo666
    Guest

    Re: on error resume next

    Imagine this case:
    A B C D
    1 "HOLA"
    2 1
    3 6
    4 25

    WITH MY CODE:
    sub gtt()
    for a=1 to 10
    cell(a,1)=cell(a,1)+cell(a,2)
    cell(c,5)="Hola" ' if the line below is error DON'T go here
    msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    next 'if error goto this next
    end sub

    the part cell(a,1)=cell(a,1)+cell(a,2) is going to fail because "HOLA"+1=Error
    but if I put something to tell VB to jump to the next value of the a and
    continues all the code, all the code is executated well.
    There are 2 way to acomplish this:
    1. if isnumeric(cells(a,1))=true then
    blalbalblablalbalba
    else
    a=a+1
    end if
    2. THE ONE I'M LOOKING FOR

    HHS
    TIA



    "Bob Phillips" wrote:

    > so what do you want to happen then?
    >
    > --
    >
    > HTH
    >
    > Bob Phillips
    >
    > (remove nothere from the email address if mailing direct)
    >
    > "filo666" <[email protected]> wrote in message
    > news:[email protected]...
    > > but, what happen if the error ocurres in other part of the macro different

    > of
    > > the loop?????
    > >
    > > "tony h" wrote:
    > >
    > > >
    > > > sub gtt()
    > > > on error goto AnError:
    > > > for a=1 to 10
    > > > cell(a,1)=cell(a,1)+cell(a,2)
    > > > cell(c,5)="Hola" ' if the line below is error DON'T go here
    > > > msgbox "Error en lo establecido " & cell(a,1) , vbokonly, "Error"
    > > > AnError:
    > > > next 'if error goto this next
    > > > end sub
    > > >
    > > >
    > > > on the basis that this is a limited loop it isn't too dangerous
    > > >
    > > >
    > > > --
    > > > tony h
    > > > ------------------------------------------------------------------------
    > > > tony h's Profile:

    > http://www.excelforum.com/member.php...o&userid=21074
    > > > View this thread:

    > http://www.excelforum.com/showthread...hreadid=505378
    > > >
    > > >

    >
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1