Recall & Review
beginner
What is a variable in VBA?
A variable is a named storage that holds data which can change while the program runs. Think of it like a labeled box where you keep information to use later.
Click to reveal answer
beginner
How do you declare a variable in VBA?
Use the
Dim statement followed by the variable name and type. For example: Dim count As Integer creates a variable named count that stores whole numbers.Click to reveal answer
beginner
What is a
For loop in VBA used for?A
For loop repeats a block of code a set number of times. It’s like telling Excel to do something over and over, counting from a start number to an end number.Click to reveal answer
intermediate
Explain the difference between
For and Do While loops in VBA.For loops run a fixed number of times decided before starting. Do While loops keep running as long as a condition is true, which might be unknown before the loop starts.Click to reveal answer
intermediate
What happens if you forget to increment the loop counter inside a
Do While loop?The loop may run forever because the condition never becomes false. This is called an infinite loop and can freeze your program.
Click to reveal answer
Which statement correctly declares a variable named 'score' as a number in VBA?
✗ Incorrect
In VBA, variables are declared using 'Dim' followed by the name and type, like 'Dim score As Integer'.
What does this VBA code do? <br>
For i = 1 To 5<br> MsgBox i<br> Next i✗ Incorrect
The 'For' loop runs from 1 to 5, showing a message box with the current number each time.
Which loop type runs while a condition is true?
✗ Incorrect
'Do While' loops continue running as long as the condition remains true.
What keyword is used to end a 'For' loop in VBA?
✗ Incorrect
The 'Next' keyword tells VBA to go to the next loop iteration or end the loop if done.
What is the risk of not changing the loop variable inside a 'Do While' loop?
✗ Incorrect
If the condition never becomes false, the loop keeps running endlessly, causing an infinite loop.
Describe how to declare and use a variable in VBA with an example.
Think about how you tell Excel to remember a number or text.
You got /5 concepts.
Explain the difference between a 'For' loop and a 'Do While' loop in VBA and when you might use each.
One counts a set number of times, the other depends on a condition.
You got /4 concepts.