Excel VBA Excel VBA Error Handling & Debugging — Questions and Answers
Question 1: Which statement is used to enable error handling and redirect execution to a labeled section in Excel VBA?
- On Error GoTo (Correct answer)
- Try...Catch
- Error Handle
- Catch Error
Correct answer: On Error GoTo
'On Error GoTo' is the VBA statement that redirects execution to a specified error handler label when a runtime error occurs.
Question 2: What does 'On Error Resume Next' do in VBA?
- Stops execution immediately when an error occurs
- Jumps to the next module in the project
- Allows execution to continue with the statement following the error (Correct answer)
- Restarts the procedure from the beginning
Correct answer: Allows execution to continue with the statement following the error
'On Error Resume Next' instructs VBA to continue executing with the statement immediately following the one that caused the error.
Question 3: Which built-in VBA object is used to retrieve information about the most recently occurring error?
- ErrInfo
- Error
- Err (Correct answer)
- LastError
Correct answer: Err
The 'Err' object contains properties like Number, Description, and Source that provide details about the last error that occurred.
Question 4: What is the purpose of the Err.Clear method in VBA?
- Deletes all error history from the workbook
- Resets the Err object's properties to their default zero/empty values (Correct answer)
- Clears the VBA error log file
- Removes error-handling code from the procedure
Correct answer: Resets the Err object's properties to their default zero/empty values
Err.Clear resets the Err object's Number, Description, and Source properties to their default values (0 and empty strings).
Question 5: In VBA, what happens if a runtime error occurs inside an active error handler?
- VBA automatically retries the failing statement
- The error is silently ignored
- The current error handler is disabled and the error propagates to the caller (Correct answer)
- VBA jumps to a nested error handler
Correct answer: The current error handler is disabled and the error propagates to the caller
If an error occurs within an error handler, VBA disables that handler and passes the error up to the calling procedure's error handler.
Question 6: Which keyword is used at the end of an error handler to return execution to the main code flow?
- Exit Handler
- Resume (Correct answer)
- Return
- End Error
Correct answer: Resume
The 'Resume' keyword directs execution back to the main code — either re-trying the error line, moving to the next line, or jumping to a specified label.
Question 7: What does 'Resume Next' do when placed inside a VBA error handler?
- Re-runs the entire procedure from the start
- Jumps to the next procedure in the module
- Continues execution with the statement after the one that caused the error (Correct answer)
- Exits the current subroutine immediately
Correct answer: Continues execution with the statement after the one that caused the error
'Resume Next' directs VBA to continue execution with the statement immediately following the line that caused the error, effectively skipping it.
Question 8: Which VBA debugging action executes code one line at a time, including stepping into called procedures?
- Breakpoints
- Step Into (Correct answer)
- Watch Window
- Immediate Window
Correct answer: Step Into
'Step Into' (F8) executes code one line at a time and enters any called Sub or Function to debug it line by line.
Question 9: What is a breakpoint in the context of VBA debugging?
- A line of code that automatically throws an error
- A marker that pauses execution when that line is reached (Correct answer)
- A special comment that stops code from running
- An error that permanently breaks the code flow
Correct answer: A marker that pauses execution when that line is reached
A breakpoint is a marker set on a specific line that causes VBA to pause execution when reached, allowing inspection of variables and program state.
Question 10: Which window in the VBA IDE allows you to type and execute VBA statements interactively without running a full procedure?
- Watch Window
- Locals Window
- Immediate Window (Correct answer)
- Output Window
Correct answer: Immediate Window
The Immediate Window (Ctrl+G) lets developers type and run VBA expressions instantly, making it ideal for testing snippets and inspecting values.
Question 11: What information does the Locals Window display during VBA debugging?
- All variables declared across the entire project
- All variables in the current procedure scope with their current values and types (Correct answer)
- A list of all VBA error numbers and descriptions
- The complete call stack of procedure invocations
Correct answer: All variables in the current procedure scope with their current values and types
The Locals Window automatically displays all variables in the currently executing procedure's scope, showing their names, types, and current values.
Question 12: Which VBA debugging feature lets you monitor a specific variable or expression and optionally pause execution when its value changes?
- Breakpoints
- Step Over
- Watch Expressions (Correct answer)
- Trace Variables
Correct answer: Watch Expressions
Watch Expressions (added via Debug > Add Watch) monitor specific variables or expressions and can pause execution when the watched value changes or meets a condition.
Question 13: What is the key difference between 'Step Into' (F8) and 'Step Over' (Shift+F8) during VBA debugging?
- Step Into runs all code at once; Step Over runs one line at a time
- Step Into enters called procedures line by line; Step Over executes them as a single step (Correct answer)
- Step Over is faster than Step Into in all scenarios
- Step Into handles errors automatically; Step Over skips them
Correct answer: Step Into enters called procedures line by line; Step Over executes them as a single step
'Step Into' descends into any called Sub or Function to debug it, while 'Step Over' executes the called procedure entirely without entering it.
Question 14: Which VBA statement outputs values and messages to the Immediate Window during code execution for logging purposes?
- Print.Debug
- Debug.Write
- Debug.Print (Correct answer)
- Console.WriteLine
Correct answer: Debug.Print
'Debug.Print' writes values or messages to the Immediate Window at runtime, which is useful for tracing variable values without stopping execution.
Question 15: What is the effect of using 'On Error GoTo 0' in a VBA procedure?
- Jumps to line number 0 of the procedure when an error occurs
- Disables any currently active error handler in the procedure (Correct answer)
- Resets the error counter variable to zero
- Enables the system-default VBA error handler
Correct answer: Disables any currently active error handler in the procedure
'On Error GoTo 0' disables the currently active error handler, causing VBA to revert to its default unhandled-error behavior for any subsequent errors.
Question 16: What does the Err.Number property return when no error has occurred in VBA?
- -1
- Nothing
- 0 (Correct answer)
- Null
Correct answer: 0
When no error has occurred, Err.Number returns 0, which is why 'If Err.Number <> 0' is the standard pattern for detecting whether an error happened.
Question 17: Which error handling approach is most appropriate for production VBA code that needs to respond differently to multiple error types?
- Place 'On Error Resume Next' at the start of every procedure
- Use a GoTo handler with a Select Case block on Err.Number (Correct answer)
- Use empty error handlers to silently ignore all errors
- Display a generic MsgBox for every error regardless of type
Correct answer: Use a GoTo handler with a Select Case block on Err.Number
A GoTo error handler with a Select Case on Err.Number lets you apply specific logic per error type, resulting in robust and maintainable error handling.
Question 18: What is 'error propagation' in VBA?
- Copying error messages between open workbooks
- An unhandled error bubbling up the call stack to the calling procedure (Correct answer)
- Automatically correcting formula errors in a worksheet
- Logging errors to an external database or file
Correct answer: An unhandled error bubbling up the call stack to the calling procedure
Error propagation occurs when a procedure has no error handler (or re-raises the error), causing the error to move up the call stack to the calling procedure.
Question 19: What is the correct syntax to raise a custom user-defined error in VBA?
- Err.Create "Custom error message"
- Err.Raise Number, Source, Description (Correct answer)
- Throw New Error("message")
- Error.Raise("Custom", 1000)
Correct answer: Err.Raise Number, Source, Description
Err.Raise allows you to generate a custom error by specifying an error number, source, and description, enabling custom error signaling within procedures.
Question 20: Which range of error numbers is reserved for user-defined errors raised with Err.Raise in VBA?
- 1 to 100
- 200 to 400
- 512 to 65535 (Correct answer)
- 1000 to 9999
Correct answer: 512 to 65535
VBA reserves error numbers 512 through 65535 for user-defined errors; numbers below 512 are reserved for VBA's built-in runtime errors.
Question 21: Which pattern ensures cleanup code (like closing files or releasing objects) always runs even if a runtime error occurs in VBA?
- Place cleanup only inside the error handler block
- Use a GoTo to an exit label for normal flow plus Resume to the same exit label from the error handler (Correct answer)
- Call cleanup exclusively at the top of each procedure
- Wrap all cleanup calls in separate On Error Resume Next blocks
Correct answer: Use a GoTo to an exit label for normal flow plus Resume to the same exit label from the error handler
Placing cleanup at an exit label, using GoTo to reach it from normal flow, and using 'Resume ExitLabel' from the error handler ensures cleanup always executes — VBA's equivalent of a 'finally' block.
Which statement is used to enable error handling and redirect execution to a labeled section in Excel VBA?
What Practice Test Geeks adds beyond an AI chat for Excel VBA
An AI chatbot can quiz you, but it can't reproduce the exam conditions or keep your record. Here you get:
- A timed, full-length Excel VBA mock exam — 50 questions in 60 minutes with a 55% pass mark, modeled on the official exam's question count and time limit, followed by a score report broken down by exam domain.
- A fixed Excel VBA question bank: the same test every attempt, so your score is comparable from one try to the next instead of changing with every regenerated quiz.
- Progress saved on your device: completed tests, scores and missed questions stay in My Progress, so you can retake only what you got wrong.
- A printable Excel VBA cheat sheet you can print or save as a PDF.
- Excel VBA flashcards built from the same question bank.
These practice questions were written with AI tools. They are not real exam questions. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy