Posted on by raymond Posted in Excel/VBATagged Excel Help, Excel Macro Expert, Freelance MS Office Developer, Learn Excel;, on Error Resume Next, VBA Expert
As a developer, you are in a position to make errors that can have awful consequences. I call them scary errors, the kind people lose their jobs over, the kind that cost real dollars. What follows is an made up example of an error I came across when I was called in to “fix a bug.”
This little bit of code looks inoffensive, but let’s delve deeper and see what evil lies hidden. It runs through the daily orders and does a bunch of stuff (hidden for the sake of brevity). It then looks up the sales tax using the customer’s state. The way its written the vlookup will throw an error if it doesn’t find the state. The resume next ignores the error. (Alaska and a few others have no sales tax.) The developer uses the fact there is an error code to infer that no sales tax is due. As youll will see and that is a bad assumption.
There’s a problem, though if the code runs into a bug in the do a bunch of stuff section where I put the note “a forced error,” it continues to run because of the ON Error Resume Next, and even though it finds a sales tax it posts as no tax. Why? Because the if finds an error code.
The state tax people are friendly lot, but you don’t want to upset them. This, in my opinion, is a misuse of error handling and as I’ve shown exceedingly dangerous. My advise, avoid On Error Resume Next.
The state tax people are friendly lot, but you don’t want to upset them. This, in my opinion, is a misuse of error handling and as I’ve shown exceedingly dangerous. My advise, avoid On Error Resume Next.