Excel VBA Flashcards
24 cards from real Excel VBA practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 20 Excel VBA flashcards as text
In VBA, which data type contains only two values?
Answer: Boolean
The `Boolean` data type in VBA is specifically designed to store logical values, which can only be `True` or `False`. Internally, `True` is typically represented as -1 and `False` as 0, but conceptually it holds only two distinct states. Other data types like `Byte`, `Long`, and `Double` can hold a much wider range of numerical values.
Which of the following formulas will produce an integer between 1 and 10, inclusive, with a probability of 10% for each integer?
Answer: INT(10*RAND())+1
The `RAND()` function in Excel generates a random decimal number between 0 (inclusive) and 1 (exclusive). Multiplying by 10 (`10*RAND()`) gives a number between 0 (inclusive) and 10 (exclusive). Applying `INT()` truncates the decimal, resulting in integers from 0 to 9. Adding 1 (`INT(10*RAND())+1`) shifts this range to 1 to 10, ensuring each integer has an equal 10% probability.
What is written at the function's end?
Answer: End Function
In VBA, every `Function` procedure must be terminated with the `End Function` statement. This keyword signals the compiler that the definition of the function has concluded. Similarly, `Sub` procedures end with `End Sub`, and `If` blocks end with `End If`.
What is the output of expression in VBA? (1O<>0 OR 0<>0) True/False
Answer: True
In VBA, the `OR` operator returns `True` if at least one of its operands is `True`. The first part of the expression, `10 <> 0`, evaluates to `True` because 10 is indeed not equal to 0. The second part, `0 <> 0`, evaluates to `False`. Since `True OR False` results in `True`, the overall expression evaluates to `True`.
In VBA, what isn't a decision statement?
Answer: None of the above
VBA includes several decision statements to control program flow based on conditions. These include the `If...Then` statement, `If...Then...Else` statement, and `If...Then...ElseIf...Else` statement. All the options A, B, and C are valid forms of decision statements in VBA. Therefore, "None of the above" is the correct answer, implying all listed options *are* decision statements.
In VBA, what is the output of expressicm 5+1 0?
Answer: 15.0
The expression `5 + 10` is a simple arithmetic addition. In VBA, `5` and `10` are treated as numerical values. Their sum is `15`. While VBA might display it as `15` or `15.0` depending on the context or variable type, `15.0` correctly represents the numerical result of the addition.
During the calculation process, rounding errors may occur.
Answer: Multiplication
Rounding errors are more prominent in multiplication because intermediate results can have many decimal places, which are then rounded. When these rounded intermediate results are used in further calculations, the small inaccuracies accumulate, leading to a noticeable error in the final product. While addition and subtraction can also involve rounding, multiplication often exacerbates the issue due to the scaling effect.
In Excel, what keyboard shortcut is used to use a breakpoint?
Answer: F9
The F9 key is the standard keyboard shortcut in the VBA editor (and many other IDEs) to toggle a breakpoint on or off at the current line of code. Breakpoints are essential debugging tools that pause code execution at a specific point, allowing developers to inspect variables and control flow. This helps in identifying and resolving errors within a macro.
What are the OR and XOR operators?
Answer: Logical Operators
OR and XOR are classified as Logical Operators in VBA. These operators are used to combine or modify Boolean expressions (expressions that evaluate to True or False). They are fundamental for controlling program flow in conditional statements and loops, allowing for complex decision-making based on multiple conditions.
What is the output of expression - 5&1O in VBA?
Answer: 510
In VBA, the ampersand symbol (`&`) is the string concatenation operator. It joins two values together as strings. Therefore, `5 & 10` concatenates the string representation of the number 5 with the string representation of the number 10, resulting in the string "510". It does not perform arithmetic addition.
VBA is based on which programming language?
Answer: Visual Basic
VBA stands for Visual Basic for Applications, and as its name suggests, it is based on the Visual Basic programming language. It is an implementation of Visual Basic built into Microsoft Office applications, allowing users to automate tasks and extend functionality within those applications. This makes it a powerful tool for customizing Excel, Word, Access, and other Office programs.
In Excel, what is the shortcut key to open the VBA editor?
Answer: ALT+F11
The keyboard shortcut `ALT+F11` is universally used in Microsoft Office applications to quickly open the Visual Basic for Applications (VBA) editor. This editor, also known as the VBE, is where you write, edit, and debug VBA code for macros. It provides access to project explorers, code windows, and other tools necessary for VBA development.
Which of the following is the default data passing method in VBA?
Answer: ByRef
In VBA, the default method for passing arguments to procedures (Sub or Function) is `ByRef` (By Reference). When an argument is passed `ByRef`, the procedure receives a pointer to the original variable's memory location, meaning any changes made to the argument within the procedure will directly affect the original variable outside the procedure. This differs from `ByVal` (By Value), which passes a copy of the variable.
When you open a workbook in Excel VBA, which event starts macros automatically?
Answer: Workbook_Open()
The `Workbook_Open()` event procedure is a special event handler in VBA that automatically executes its code whenever the workbook containing it is opened. This event is commonly used to perform initial setup tasks, such as displaying a welcome message, updating data, or setting specific sheet properties, ensuring the workbook is ready for use upon opening. It resides in the `ThisWorkbook` module.
In VBA, what data type is used to store decimal values?
Answer: Double
The `Double` data type in VBA is specifically designed to store floating-point numbers, which are numbers with decimal values. It provides high precision and a wide range for both positive and negative numbers. While `Single` also stores decimal values, `Double` offers greater precision and is generally preferred for most calculations involving non-integer numbers.
Which part of the VBA window corresponds to the code-writing area?
Answer: Module
In the VBA editor, code is primarily written within modules. A module is a container for procedures (Subroutines and Functions) and declarations. When you insert a new module, a blank code window appears where you can type your VBA code. While procedures and functions are *types* of code blocks, the module is the actual file-like object that holds the code.
In VBA, which of the following statements is not a looping statement?
Answer: If Then Goto
`If Then Goto` is a conditional statement combined with an unconditional jump, not a looping construct. It executes a block of code if a condition is true and then can jump to a specified label. In contrast, `For Next`, `Do While`, and `Do Until` are all dedicated looping statements designed to repeatedly execute a block of code until a certain condition is met or a specified number of iterations is completed.
What in VBA does not return a value?
Answer: Subroutine
In VBA, a `Subroutine` (declared with `Sub...End Sub`) is a block of code designed to perform a specific task but does not return a value to the calling code. Its purpose is to execute actions or modify variables directly. Conversely, a `Function` (declared with `Function...End Sub`) is designed to compute and return a single value to the part of the code that called it.
In VBA, what character indicates the start of a comment?
Answer: '
In VBA, the single apostrophe character (`'`) is used to denote the start of a comment. Any text following the apostrophe on that line will be ignored by the VBA interpreter during execution. Comments are crucial for code readability and documentation, helping developers understand the purpose and logic of their code.
The term "attached text" refers to text that is attached to a cell.
Answer: Comment
In Excel, a "comment" is a small note or piece of text that can be attached to a specific cell. It provides additional information or context about the cell's content without altering the cell's value itself. Comments are indicated by a small red triangle in the corner of the cell and can be viewed by hovering over the cell or right-clicking.