0
0
Excelspreadsheet~5 mins

Variables and loops in VBA in Excel - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ADim score As Integer
BVar score = 0
CDeclare score Number
DSet score = Integer
What does this VBA code do? <br>For i = 1 To 5<br> MsgBox i<br> Next i
AShows one message box with number 5
BCreates 5 message boxes at once
CShows message boxes with numbers 1 to 5 one by one
DDoes nothing
Which loop type runs while a condition is true?
AFor loop
BDo While loop
CSelect Case
DIf statement
What keyword is used to end a 'For' loop in VBA?
AEnd For
BLoop
CExit
DNext
What is the risk of not changing the loop variable inside a 'Do While' loop?
AThe loop may run forever (infinite loop)
BThe loop will never run
CThe loop will run only once
DThe loop will skip iterations
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.