From the course: Excel: Learning VBA

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Debug your VBA code

Solution: Debug your VBA code - Microsoft Excel Tutorial

From the course: Excel: Learning VBA

Solution: Debug your VBA code

(lively music) - [Instructor] All right. I hope you had fun with the challenges for debugging your Excel VBA code. In this movie, I will use the sample file 04_07_solution to show you how I might do it. I'm not actually working with any data in the workbook, so I'll press ALT F11 to move to the Visual Basic Editor. In the Visual Basic Editor, I have my code module. And to start, I need to add an on error line to send the routine to a line named if error. And here's how I did that. I have on error, again, it's two separate words and then goto as one word. And that's where a lot of confusion can happen. Instead of on error being one word and go to being two, in fact, it's the other way around. And the line label is if error, followed by a colon and the colon is important. Right, then the code runs, assuming there was no error. And to exit the subroutine, you use exit sub. That way no additional code will run within the…

Contents