Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
On Error Resume Next
I have seen "On Error Resume Next" in several different
macros but do not fully understand how it works. Any help would be greatly appreciated. Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
On Error Resume Next
AFAIK it means what it says. If you encounter something that would cause an
error to stop your code, just ignore it and go on to the next thing which may work. This may be good but it might ignore something you need to know about. -- Don Guillett SalesAid Software "Mike" wrote in message ... I have seen "On Error Resume Next" in several different macros but do not fully understand how it works. Any help would be greatly appreciated. Thanks |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
On Error Resume Next
If a line of code is encountered that causes an error, "On Error Resume
Next" will not process that line of code but will resume execution on the following line. "On Error Resume Next" is quite handy if you want to handle errors "in-line" rather than running a sub and ending the procedu On Error Resume Next 'Some line of code that returns an error here If err.number = ErrorCodeToCheckFor then 'Do some stuff to handle the error err.clear -- Michael Hopwood (Phobos) "Mike" wrote in message ... I have seen "On Error Resume Next" in several different macros but do not fully understand how it works. Any help would be greatly appreciated. Thanks |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
On Error Resume Next
Mike
Don and Michael gave you good info on what it does. I just want to add one point. Be aware that the instruction "On Error Resume Next" remains in force until the end (End Sub or Exit Sub) of the current procedure. This is of no consequence to you if the procedure consists of only the line that you anticipated an error on. But if you have other things happening in the code besides the one line that you thought might cause an error, you can have a problem. If an error were to occur later but still in the same procedure, Excel would simply "Resume Next". Then you would run around chasing your tail trying to figure out why the data is not what you expected. Been there. You should always reinstate Excel's normal error procedures immediately after the line that could cause the error. For example: Sub MyMacro() 'Some code On Error Resume Next 'The line that might cause an error On Error GoTo 0 'More code End Sub The "On Error GoTo 0" returns error handling back to normal or default. HTH Otto "Mike" wrote in message ... I have seen "On Error Resume Next" in several different macros but do not fully understand how it works. Any help would be greatly appreciated. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
On error resume next not working | Excel Discussion (Misc queries) | |||
Autofill & On Error Resume Next | Excel Discussion (Misc queries) | |||
On Error Resume Next problem | Excel Discussion (Misc queries) | |||
On error resume next problem | Excel Discussion (Misc queries) |