0
0
Excelspreadsheet~10 mins

Variables and loops in VBA in Excel - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable named count as Integer.

Excel
Dim count As [1]
Drag options to blanks, or click blank then click option'
AString
BBoolean
CInteger
DDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of Integer for numbers.
Forgetting to declare the variable type.
2fill in blank
medium

Complete the code to start a For loop that counts from 1 to 5 using variable i.

Excel
For i = 1 To [1]
    ' Your code here
Next i
Drag options to blanks, or click blank then click option'
A5
B10
C0
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using 10 instead of 5 for the loop limit.
Using 0 which would not run the loop as expected.
3fill in blank
hard

Fix the error in the loop that sums numbers from 1 to 3 into variable total.

Excel
Dim total As Integer
total = 0
For j = 1 To 3
    total = total [1] j
Next j
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication or division instead of addition.
Using subtraction which would decrease the total.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers from 1 to 4 using variable k.

Excel
For [1] = 1 To [2]
    Debug.Print k
Next k
Drag options to blanks, or click blank then click option'
Ak
Bi
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than k.
Setting the upper limit to 5 instead of 4.
5fill in blank
hard

Fill all three blanks to create a loop that stores squares of numbers 1 to 3 in an array arr.

Excel
Dim arr(1 To 3) As Integer
Dim n As Integer
For [1] = 1 To [2]
    arr([3]) = n * n
Next n
Drag options to blanks, or click blank then click option'
An
B3
Di
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for loop and array index.
Setting the loop limit incorrectly.