on error explination

chris2727272727

Board Regular
Joined
Jul 10, 2005
Messages
152
range ("a2").formula = (vlookup(WHAT TO LOOK UP)

Can anybody explain to me the way the on error statement works ie if i have the above text and want it to break the sub do i put an on error end sub before or after the above vlookup statment and do i need a on error statement for every line of code or will one on error end sub at the beggining of the sub routine suffice for all the text.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
on error in itself will just cause the code to break and do what ever you tell it to, one on eror statemnet will work at the beggining of your code if you alway swant it to do the same thing when it errors, if you want the code to just continue on the next instruction after an error then
on error resume next

is what you need. If you want the code to exit the routine altogether then try something like this

Sub yourcode ()

On error gotto errortrap:

your code goes here

exit sub
errortrap:
exit sub

end sub
 
Upvote 0
Chris

On Error works with errors in VBA code.

Are you trying to trap an error in the Vlookup?
 
Upvote 0

Forum statistics

Threads
1,224,209
Messages
6,177,155
Members
452,762
Latest member
manuha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top