Challenge - 5 Problems
VBA Procedure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📊 Formula Result
intermediate2:00remaining
What is the output of this VBA procedure?
Consider this VBA code in Excel:
What happens when you run
Sub ShowMessage() MsgBox "Hello, Excel!" End Sub
What happens when you run
ShowMessage?Excel
Sub ShowMessage()
MsgBox "Hello, Excel!"
End SubAttempts:
2 left
💡 Hint
MsgBox shows a popup message box with the text you give it.
✗ Incorrect
The MsgBox function in VBA displays a popup message box with the text inside the quotes. So running ShowMessage shows a box with "Hello, Excel!".
❓ Function Choice
intermediate2:00remaining
Which VBA procedure clears the contents of cell A1?
You want a VBA procedure that clears the content of cell A1 on the active worksheet. Which code does this correctly?
Attempts:
2 left
💡 Hint
ClearContents removes the content but keeps formatting.
✗ Incorrect
Option A uses ClearContents which removes the cell's content but keeps formatting intact. Option A deletes the cell which shifts cells and is not recommended. Option A sets the value to empty string which looks empty but is not the same as clearing. Option A clears content and formatting, which is more than asked.
🎯 Scenario
advanced2:00remaining
You want to create a VBA procedure that adds 10 to the value in cell B2. Which code works correctly?
You have a number in cell B2. You want a VBA procedure that adds 10 to that number and puts the result back in B2. Which code does this correctly?
Attempts:
2 left
💡 Hint
Use the Value property to read and write cell values.
✗ Incorrect
Option B correctly reads the value from B2, adds 10, and writes it back. Option B lacks explicit .Value (uses default property) and is less preferred. Option B also works correctly but is not the best answer because it uses Cells notation (valid but less clear). Option B uses .Text which is read-only and cannot be assigned to.
📊 Formula Result
advanced2:00remaining
What error does this VBA procedure cause?
Look at this VBA code:
What happens when you run
Sub TestError() Dim x As Integer x = "Hello" End Sub
What happens when you run
TestError?Excel
Sub TestError()
Dim x As Integer
x = "Hello"
End SubAttempts:
2 left
💡 Hint
You cannot assign text to an Integer variable.
✗ Incorrect
Variable x is declared as Integer but assigned a string "Hello". This causes a Type Mismatch error at runtime because the types do not match.
❓ data_analysis
expert2:00remaining
How many cells will be colored after running this VBA procedure?
Consider this VBA code:
Assuming cells A1 to A5 contain the values: 5, 12, 8, 15, 20 respectively, how many cells will be colored yellow after running
Sub ColorCells()
Dim i As Integer
For i = 1 To 5
If Cells(i, 1).Value > 10 Then
Cells(i, 1).Interior.Color = vbYellow
End If
Next i
End SubAssuming cells A1 to A5 contain the values: 5, 12, 8, 15, 20 respectively, how many cells will be colored yellow after running
ColorCells?Excel
Sub ColorCells() Dim i As Integer For i = 1 To 5 If Cells(i, 1).Value > 10 Then Cells(i, 1).Interior.Color = vbYellow End If Next i End Sub
Attempts:
2 left
💡 Hint
Count how many values in A1:A5 are greater than 10.
✗ Incorrect
Values greater than 10 are in cells A2 (12), A4 (15), and A5 (20). So 3 cells get colored yellow.