Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

on error resume next

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
filo666 - 26 Jan 2006 16:41 GMT
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
tony h - 26 Jan 2006 16:49 GMT
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

Signature

tony h

filo666 - 26 Jan 2006 17:26 GMT
but, what happen if the error ocurres in other part of the macro different of
the loop?????

> sub gtt()
> on error goto AnError:
[quoted text clipped - 7 lines]
>
> on the basis that this is a limited loop it isn't too dangerous
Jim Thomlinson - 26 Jan 2006 17:45 GMT
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.
Signature

HTH...

Jim Thomlinson

> but, what happen if the error ocurres in other part of the macro different of
> the loop?????
[quoted text clipped - 10 lines]
> >
> > on the basis that this is a limited loop it isn't too dangerous
filo666 - 26 Jan 2006 17:51 GMT
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???

> 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.
[quoted text clipped - 14 lines]
> > >
> > > on the basis that this is a limited loop it isn't too dangerous
Jim Thomlinson - 26 Jan 2006 18:01 GMT
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

Signature

HTH...

Jim Thomlinson

> 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....
[quoted text clipped - 19 lines]
> > > >
> > > > on the basis that this is a limited loop it isn't too dangerous
Bob Phillips - 26 Jan 2006 18:06 GMT
so what do you want to happen then?

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

> but, what happen if the error ocurres in other part of the macro different of
> the loop?????
[quoted text clipped - 16 lines]
> > tony h's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=21074
> > View this thread: http://www.excelforum.com/showthread.php?threadid=505378
filo666 - 26 Jan 2006 18:42 GMT
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

> so what do you want to happen then?
>
[quoted text clipped - 29 lines]
> > > View this thread:
> http://www.excelforum.com/showthread.php?threadid=505378
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.