Excel VBA Excel VBA Fundamentals & Syntax 1 — Questions and Answers
Question 1: Which keyword is used to declare a variable in VBA?
- Var
- Dim (Correct answer)
- Let
- Define
Correct answer: Dim
In VBA, the Dim keyword is used to declare variables before they are used.
Question 2: What is the correct way to start a VBA subroutine?
- Function MySub()
- Sub MySub() (Correct answer)
- Begin MySub()
- Start MySub()
Correct answer: Sub MySub()
A VBA subroutine begins with the Sub keyword followed by the subroutine name and parentheses.
Question 3: Which VBA data type stores True or False values?
- Integer
- String
- Boolean (Correct answer)
- Byte
Correct answer: Boolean
The Boolean data type in VBA holds only True or False values.
Question 4: What does the Option Explicit statement do in VBA?
- Enables error handling
- Requires all variables to be declared before use (Correct answer)
- Optimizes code performance
- Enables access to Excel objects
Correct answer: Requires all variables to be declared before use
Option Explicit forces the programmer to explicitly declare all variables, reducing bugs caused by typos.
Question 5: In VBA, which operator is used for string concatenation?
- +
- *
- & (Correct answer)
- #
Correct answer: &
The ampersand (&) operator is the standard VBA operator for joining strings together.
Question 6: Which VBA loop construct checks its condition BEFORE executing the loop body?
- Do...Loop Until
- Do Until...Loop (Correct answer)
- For Each...Next
- Do...Loop While
Correct answer: Do Until...Loop
Do Until...Loop evaluates the condition before each iteration and stops when the condition is True.
Which keyword is used to declare a variable in VBA?