×

Multiple-Choice Questions

Web Technologies MCQs

Computer Science Subjects MCQs

Databases MCQs

Programming MCQs

Testing Software MCQs

Digital Marketing Subjects MCQs

Cloud Computing Softwares MCQs

AI/ML Subjects MCQs

Engineering Subjects MCQs

Office Related Programs MCQs

Management MCQs

More

VBA MCQs (Multiple-Choice Questions)

Practice these VBA MCQs (Multiple-Choice Questions) with answers and explanations to test your knowledge of Visual Basic for Applications, VBA programming concepts, variables, procedures, arrays, loops, error handling, Excel objects, ranges, worksheets, workbooks, events, UserForms, and automation.

VBA MCQs

These VBA multiple-choice questions cover fundamental and practical concepts used when developing macros and automating Microsoft Office applications, especially Microsoft Excel.

List of VBA MCQs

Here is a collection of VBA MCQs with answers and explanations for interview preparation, examinations, and practice.

1. What does VBA stand for?

  1. Visual Basic for Applications
  2. Visual Business Automation
  3. Virtual Basic Application
  4. Visual Basic Architecture

Answer: A) Visual Basic for Applications

Explanation:

VBA stands for Visual Basic for Applications. It is Microsoft's programming language for automating and extending Office applications such as Excel, Word, and Access.

2. Which VBA statement forces variables to be explicitly declared?

  1. Option Base
  2. Option Explicit
  3. Option Compare
  4. Option Private Module

Answer: B) Option Explicit

Explanation:

Option Explicit requires variables to be declared before they are used. This helps detect spelling mistakes and unintended undeclared variables.

3. Which statement correctly declares an Integer variable in VBA?

  1. Integer count
  2. Dim count As Integer
  3. Declare count Integer
  4. Var count As Integer

Answer: B) Dim count As Integer

Explanation:

The Dim statement declares a variable. The As Integer clause specifies its data type.

4. Which VBA data type is commonly used to store text?

  1. Boolean
  2. Date
  3. String
  4. Double

Answer: C) String

Explanation:

The String data type stores character and text data in VBA.

5. Which VBA data type can store True or False?

  1. Boolean
  2. Byte
  3. Integer
  4. Currency

Answer: A) Boolean

Explanation:

The Boolean data type represents two logical values: True and False.

6. Which keyword is used to assign an object reference to an object variable?

  1. Let
  2. Set
  3. Assign
  4. Object

Answer: B) Set

Explanation:

The Set statement assigns an object reference to an object variable, such as Set ws = Worksheets(1).

7. Which procedure type does not return a value directly to its caller?

  1. Function
  2. Property Get
  3. Sub
  4. Function returning Double

Answer: C) Sub

Explanation:

A Sub procedure performs actions but does not return a value through its procedure name. A Function can return a value.

8. Which is the correct declaration of a VBA Function that returns a Long value?

  1. Function Total() As Long
  2. Function Total Long()
  3. Long Function Total()
  4. Function As Long Total()

Answer: A) Function Total() As Long

Explanation:

A VBA Function specifies its return type after the parameter list using the As clause.

9. Which keyword is used to declare a constant in VBA?

  1. Static
  2. Const
  3. Fixed
  4. Constant

Answer: B) Const

Explanation:

The Const statement declares a named constant whose value cannot be changed during program execution.

10. What is the purpose of the VBA Variant data type?

  1. It can hold different kinds of values
  2. It can only store integers
  3. It can only store object references
  4. It is used only for arrays

Answer: A) It can hold different kinds of values

Explanation:

Variant is a flexible VBA data type that can contain different kinds of data, including numbers, strings, dates, and objects under appropriate conditions.

11. Which symbol begins a single-line comment in VBA?

  1. //
  2. #
  3. '
  4. --

Answer: C) '

Explanation:

An apostrophe starts a comment in VBA. The remainder of that line is treated as a comment and is not executed as VBA code.

12. Which VBA statement is used to conditionally execute code?

  1. If...Then
  2. Loop...Next
  3. With...End With
  4. Declare...End Declare

Answer: A) If...Then

Explanation:

If...Then evaluates a condition and executes code depending on whether the condition is true.

13. Which VBA structure is useful when comparing one expression against several possible values?

  1. Select Case
  2. For Each
  3. With
  4. Do Loop

Answer: A) Select Case

Explanation:

Select Case provides a convenient way to test one expression against multiple possible cases.

14. Which loop is specifically designed to iterate through each element of a collection or array?

  1. For Each...Next
  2. If...Then
  3. Select Case
  4. With...End With

Answer: A) For Each...Next

Explanation:

For Each...Next iterates through each element of an array, collection, or other supported enumerable object.

15. Which VBA loop executes while a condition remains True?

  1. Do While...Loop
  2. For...Next only
  3. Select Case
  4. With...End With

Answer: A) Do While...Loop

Explanation:

Do While...Loop continues executing its body while the specified condition evaluates to True.

16. What does the Exit For statement do?

  1. Restarts the loop
  2. Exits the current For loop
  3. Exits the entire VBA project
  4. Skips compilation

Answer: B) Exits the current For loop

Explanation:

Exit For immediately terminates the current For or For Each loop and continues execution after the loop.

17. Which operator is commonly used for string concatenation in VBA?

  1. +
  2. &
  3. *
  4. :

Answer: B) &

Explanation:

The & operator concatenates strings in VBA. For example, "Hello " & "World" produces "Hello World".

18. Which function returns the number of characters in a string?

  1. Count
  2. Length
  3. Len
  4. Size

Answer: C) Len

Explanation:

The VBA Len function returns the number of characters in a string.

19. Which VBA function returns characters from the beginning of a string?

  1. Left
  2. Start
  3. Begin
  4. First

Answer: A) Left

Explanation:

The Left function returns a specified number of characters from the left side of a string.

20. Which VBA function extracts characters beginning at a specified position in a string?

  1. Mid
  2. Part
  3. Slice
  4. Extract

Answer: A) Mid

Explanation:

The Mid function extracts a specified number of characters beginning at a specified position within a string.

21. Which VBA function converts a string to uppercase?

  1. Upper
  2. UCase
  3. ToUpper
  4. UpperCase

Answer: B) UCase

Explanation:

The UCase function returns a string converted to uppercase letters.

22. Which function can be used to remove leading and trailing spaces from a string?

  1. Clean
  2. Trim
  3. Strip
  4. RemoveSpace

Answer: B) Trim

Explanation:

The VBA Trim function removes leading and trailing spaces from a string.

23. Which function converts a numeric value or expression to a Long value?

  1. CLng
  2. CIntOnly
  3. LongValue
  4. ToLong

Answer: A) CLng

Explanation:

CLng converts an expression to the Long data type, subject to the normal VBA conversion rules.

24. Which VBA function is commonly used to display a dialog box containing a message?

  1. MsgBox
  2. DialogBox
  3. Message
  4. ShowDialog

Answer: A) MsgBox

Explanation:

The MsgBox function displays a message box and can also provide buttons and return information about the user's selection.

25. Which function is used to obtain input from the user through a simple dialog box?

  1. InputBox
  2. UserInput
  3. GetInput
  4. ReadBox

Answer: A) InputBox

Explanation:

The InputBox function displays a prompt and allows the user to enter a value.

26. Which statement is used to handle runtime errors using a designated error-handling procedure?

  1. On Error GoTo
  2. Handle Error
  3. Catch Error
  4. Error Handle

Answer: A) On Error GoTo

Explanation:

On Error GoTo enables a procedure to transfer control to a specified label when a runtime error occurs.

27. Which object represents a worksheet in the Excel VBA object model?

  1. Worksheet
  2. SheetObject
  3. ExcelPage
  4. WorkPage

Answer: A) Worksheet

Explanation:

The Worksheet object represents an individual worksheet in an Excel workbook.

28. Which object represents an Excel workbook?

  1. Workbook
  2. ExcelFile
  3. WorkFile
  4. BookObject

Answer: A) Workbook

Explanation:

The Workbook object represents an Excel workbook and provides access to its worksheets and other workbook-level members.

29. Which Excel VBA object represents a cell or range of cells?

  1. Range
  2. CellGroup
  3. CellSet
  4. DataArea

Answer: A) Range

Explanation:

The Range object represents a cell, a range of cells, or another supported range of cells in an Excel worksheet.

30. What does the following VBA statement do?

Worksheets("Sheet1").Range("A1").Value = 100
  1. Creates a new worksheet named Sheet1
  2. Places 100 into cell A1 of Sheet1
  3. Deletes the value from A1
  4. Formats A1 as currency

Answer: B) Places 100 into cell A1 of Sheet1

Explanation:

The statement accesses Sheet1, references cell A1 through the Range object, and assigns the value 100 to its Value property.

31. Which property returns the value stored in an Excel Range?

  1. Value
  2. Content
  3. Data
  4. TextValue

Answer: A) Value

Explanation:

The Value property gets or sets the value of a range. It is commonly used to read or write cell contents through VBA.

32. Which property returns the displayed text of a single Excel cell?

  1. Value
  2. Text
  3. DisplayValue
  4. Caption

Answer: B) Text

Explanation:

The Text property returns the formatted text for a cell as displayed, subject to the cell's width and formatting.

33. Which VBA statement activates a specific worksheet?

  1. Worksheets("Sheet1").Activate
  2. Worksheets("Sheet1").Open
  3. Worksheets("Sheet1").Start
  4. Worksheets("Sheet1").SelectPage

Answer: A) Worksheets("Sheet1").Activate

Explanation:

The Activate method makes the specified worksheet the active worksheet.

34. Which method saves the current Excel workbook?

  1. Save
  2. Store
  3. Write
  4. Commit

Answer: A) Save

Explanation:

The Save method saves changes made to a workbook.

35. Which method can be used to save an Excel workbook under a different file name or format?

  1. SaveAs
  2. SaveNew
  3. StoreAs
  4. ExportAsFile

Answer: A) SaveAs

Explanation:

The SaveAs method saves a workbook with a specified name, location, or file format.

36. Which method is used to add a new worksheet to an Excel workbook?

  1. Add
  2. InsertSheet
  3. NewSheet
  4. CreateWorksheet

Answer: A) Add

Explanation:

The Add method of the Worksheets collection can be used to create a new worksheet.

37. Which statement correctly deletes a worksheet object named Sheet2?

  1. Worksheets("Sheet2").Delete
  2. Worksheets("Sheet2").Remove
  3. Worksheets("Sheet2").Erase
  4. Worksheets("Sheet2").Clear

Answer: A) Worksheets("Sheet2").Delete

Explanation:

The Delete method removes the specified worksheet from the workbook. Excel may display a confirmation prompt depending on application settings.

38. Which Excel VBA property can be used to determine the last used row in a particular column by searching upward?

  1. Cells(Rows.Count, 1).End(xlUp).Row
  2. Cells(1, Rows.Count).LastRow
  3. Rows.LastUsed(1)
  4. Columns(1).EndRow

Answer: A) Cells(Rows.Count, 1).End(xlUp).Row

Explanation:

This pattern starts from the bottom of column A and uses End(xlUp) to move to the nearest populated cell above, with Row returning its row number.

39. Which VBA statement is used to execute a procedure from another procedure?

  1. Call
  2. RunOnly
  3. ExecuteProc
  4. InvokeSub

Answer: A) Call

Explanation:

The Call statement transfers control to a Sub, Function, or supported procedure. For a Sub, the Call keyword is optional in many cases.

40. What is the main purpose of the With...End With statement?

  1. To repeatedly reference the same object without writing its full expression
  2. To create a new object automatically
  3. To declare a global variable
  4. To handle runtime errors

Answer: A) To repeatedly reference the same object without writing its full expression

Explanation:

With...End With lets multiple statements operate on the same object without repeatedly specifying the complete object expression.

41. Which keyword is used to specify that a procedure parameter should receive a copy of the argument's value?

  1. ByRef
  2. ByVal
  3. CopyVal
  4. ValueRef

Answer: B) ByVal

Explanation:

ByVal passes an argument by value, whereas ByRef passes a reference to the variable, allowing the called procedure to modify the caller's variable under the applicable rules.

42. Which keyword can be used to declare a variable whose value persists between calls to a procedure?

  1. Static
  2. Persist
  3. Permanent
  4. Retain

Answer: A) Static

Explanation:

A local variable declared with Static retains its value between calls to the procedure in which it is declared.

43. Which statement declares a dynamic array that can later be resized?

  1. Dim values() As Long
  2. Dim values(10) As Long
  3. Dynamic values As Long
  4. Array values() As Long

Answer: A) Dim values() As Long

Explanation:

An array declared without bounds, such as Dim values() As Long, can later be dimensioned with ReDim.

44. Which statement resizes an array while preserving its existing elements?

  1. ReDim Preserve
  2. Resize Preserve
  3. Preserve Array
  4. ReSize Keep

Answer: A) ReDim Preserve

Explanation:

ReDim Preserve changes the size of a dynamic array while retaining its existing values, subject to VBA's array resizing rules.

45. Which Excel VBA event procedure commonly runs when a workbook is opened?

  1. Workbook_Open
  2. Workbook_Start
  3. Workbook_Load
  4. Workbook_Begin

Answer: A) Workbook_Open

Explanation:

Workbook_Open is a workbook event procedure that runs when the workbook is opened, provided events are enabled and the procedure is placed in the appropriate workbook module.

46. In Excel VBA, where is the Worksheet_Change event procedure normally placed?

  1. In the relevant worksheet module
  2. Only in a standard module
  3. Only in the ThisWorkbook module
  4. In the Immediate window

Answer: A) In the relevant worksheet module

Explanation:

The Worksheet_Change event belongs to a worksheet object and is normally written in the module for the worksheet whose changes should trigger the event.

47. Which VBA window is primarily used to execute individual VBA statements interactively while debugging?

  1. Immediate Window
  2. Properties Window
  3. Project Explorer
  4. Object Browser

Answer: A) Immediate Window

Explanation:

The Immediate Window in the Visual Basic Editor can be used to execute VBA statements interactively and inspect values while debugging code.

48. What is the purpose of a breakpoint in VBA debugging?

  1. To pause execution at a specified line
  2. To permanently delete a procedure
  3. To convert VBA into compiled machine code
  4. To prevent a workbook from opening

Answer: A) To pause execution at a specified line

Explanation:

A breakpoint pauses program execution at a selected line so that variables, object states, and program flow can be inspected during debugging.

49. What is the result of the following VBA code?

Dim total As Long
total = 10

If total > 5 Then
total = total + 20
End If
  1. total becomes 5
  2. total becomes 10
  3. total becomes 30
  4. The code generates a syntax error

Answer: C) total becomes 30

Explanation:

The initial value of total is 10. Since 10 is greater than 5, the If block executes and adds 20, resulting in 30.

50. What does the following Excel VBA code do?

Dim ws As Worksheet
Set ws = Worksheets("Sheet1")

With ws.Range("A1:A5")
.Value = 10
.Font.Bold = True
End With
  1. Deletes A1:A5 and creates a new range
  2. Places 10 in A1:A5 and makes the cells bold
  3. Places 10 only in A1 and makes Sheet1 bold
  4. Creates five new worksheets and assigns each a value of 10

Answer: B) Places 10 in A1:A5 and makes the cells bold

Explanation:

The code assigns the value 10 to every cell in the range A1:A5. The With block then sets the Font.Bold property of that same range to True, making the five cells bold.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2026 www.includehelp.com. All rights reserved.