Excel VBA Excel VBA Fundamentals & Syntax 2 — Questions and Answers
Question 1: What is the VBA constant for a newline character in a message box?
- vbTab
- vbNewLine
- vbCrLf (Correct answer)
- vbNull
Correct answer: vbCrLf
vbCrLf inserts a carriage return and line feed to create a new line in strings and message boxes.
Question 2: How do you write a comment in VBA code?
- // comment
- /* comment */
- ' comment (Correct answer)
- -- comment
Correct answer: ' comment
In VBA, a single apostrophe (') at the start of a line or inline makes the rest of the text a comment.
Question 3: What value does an uninitialized numeric variable hold in VBA?
- Null
- Empty
- 0 (Correct answer)
- Nothing
Correct answer: 0
Uninitialized numeric variables in VBA default to 0 automatically.
Question 4: Which VBA function converts a string to uppercase?
- Upper()
- ToUpper()
- UCase() (Correct answer)
- StrUpper()
Correct answer: UCase()
UCase() is the VBA built-in function that converts all characters in a string to uppercase.
Question 5: What is the result of the VBA expression: 7 Mod 3?
- 2
- 1 (Correct answer)
- 3
- 4
Correct answer: 1
The Mod operator returns the remainder of integer division, so 7 divided by 3 leaves a remainder of 1.
Question 6: In VBA, which scope modifier makes a variable visible throughout the entire module?
- Private (Correct answer)
- Public
- Dim
- Static
Correct answer: Private
A variable declared with Private at module level is accessible to all procedures within that module only.
What is the VBA constant for a newline character in a message box?