Excel VBA Excel VBA 3 — Questions and Answers
Question 1: Which VBA event fires when a cell's value is changed by the user on a worksheet?
- Worksheet_Change (Correct answer)
- Worksheet_Edit
- Worksheet_Update
- Worksheet_Modify
Correct answer: Worksheet_Change
The Worksheet_Change event fires whenever a user or external link changes a cell in the worksheet.
Question 2: What does Application.ScreenUpdating = False do in a VBA macro?
- Prevents the screen from refreshing while the macro runs (Correct answer)
- Hides the Excel window entirely
- Disables formula recalculation
- Turns off all events
Correct answer: Prevents the screen from refreshing while the macro runs
Setting ScreenUpdating to False stops the screen from flickering during macro execution, improving speed.
Question 3: Which function returns the number of characters in a string in VBA?
- Len (Correct answer)
- Count
- Size
- Length
Correct answer: Len
Len(string) returns the number of characters contained in the string argument.
Question 4: In VBA, what does the keyword 'Me' refer to inside a UserForm's code module?
- The UserForm itself (Correct answer)
- The active workbook
- The calling procedure
- The parent worksheet
Correct answer: The UserForm itself
Me refers to the instance of the class (UserForm, worksheet, or workbook) in whose code module it appears.
Question 5: What VBA construct handles errors that occur during runtime?
- On Error GoTo (Correct answer)
- Try...Catch
- Error...Handle
- Catch...Finally
Correct answer: On Error GoTo
VBA uses On Error GoTo [label] to redirect execution to an error-handling block when a runtime error occurs.
Question 6: Which property of a Range object returns the number of rows in that range?
- Rows.Count (Correct answer)
- RowCount
- CountRows
- Rows.Total
Correct answer: Rows.Count
Range.Rows.Count returns an integer representing how many rows are in the specified range.
Question 7: What is the VBA equivalent of Excel's VLOOKUP function when searching a sorted array?
- Application.WorksheetFunction.VLookup (Correct answer)
- VBA.VLookup
- Range.VLookup
- Excel.VLookup
Correct answer: Application.WorksheetFunction.VLookup
Application.WorksheetFunction.VLookup lets you call Excel's built-in VLOOKUP from within VBA code.
Which VBA event fires when a cell's value is changed by the user on a worksheet?