0
0
Excelspreadsheet~20 mins

Simple VBA procedures in Excel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
VBA Procedure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📊 Formula Result
intermediate
2:00remaining
What is the output of this VBA procedure?
Consider this VBA code in Excel:
Sub ShowMessage()
  MsgBox "Hello, Excel!"
End Sub

What happens when you run ShowMessage?
Excel
Sub ShowMessage()
  MsgBox "Hello, Excel!"
End Sub
AExcel crashes with an error
BThe text "Hello, Excel!" is written into the active cell
CNothing happens because MsgBox is not a valid VBA command
DA message box appears showing the text "Hello, Excel!"
Attempts:
2 left
💡 Hint
MsgBox shows a popup message box with the text you give it.
Function Choice
intermediate
2: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?
A
Sub ClearA1()
  Range("A1").ClearContents
End Sub
B
Sub ClearA1()
  Range("A1").Clear
End Sub
C
Sub ClearA1()
  Range("A1").Value = ""
End Sub
D
Sub ClearA1()
  Cells(1, 1).Delete
End Sub
Attempts:
2 left
💡 Hint
ClearContents removes the content but keeps formatting.
🎯 Scenario
advanced
2: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?
A
Sub AddTen()
  Range("B2") = Range("B2") + 10
End Sub
B
Sub AddTen()
  Range("B2").Value = Range("B2").Value + 10
End Sub
C
Sub AddTen()
  Cells(2, 2).Value = Cells(2, 2).Value + 10
End Sub
D
Sub AddTen()
  Range("B2").Text = Range("B2").Text + 10
End Sub
Attempts:
2 left
💡 Hint
Use the Value property to read and write cell values.
📊 Formula Result
advanced
2:00remaining
What error does this VBA procedure cause?
Look at this VBA code:
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 Sub
ASyntax error when compiling
BNo error, x becomes 0
CType Mismatch error at runtime
DVariable x stores the string "Hello"
Attempts:
2 left
💡 Hint
You cannot assign text to an Integer variable.
data_analysis
expert
2:00remaining
How many cells will be colored after running this VBA procedure?
Consider this VBA code:
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

Assuming 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
A3
B2
C5
D0
Attempts:
2 left
💡 Hint
Count how many values in A1:A5 are greater than 10.