linkedin-skill-assessments-quizzes

Visual Basic for Applications (VBA)

Q1. Which two sets of values are printed by this function and sub?

Function GetVitals(ID As Long, Age As Long, Optional Weight As Long) As String
    GetVitals="ID=" & ID &"Age=" & Age & "Weight=" & Weight
End Function
Sub ShowVitals()
    Dim ID As Long, Age As Long,Weight as Long
    Debug.Print GetVitals(ID:=5,Age:=20)
    Debug.Print GetVitals(ID:=6,Age:=25,Weight:=130)
End Sub
ID=5 Age = 20 Weight=
ID=6 Age = 25 Weight=130
ID=5 Age = 20 Weight=0
ID=6 Age = 25 Weight=130
ID=5 Age = 20 Weight=Null
ID=6 Age = 25 Weight=130
ID=5 Age = 20
ID=6 Age = 25 Weight=130

Q2. This code shows the first statement of CalledSub. Which calling statement will work properly?

Sub CalledSub(Surname, Age)

Q3. What is the principal difference between a class and an object?

Q4. What value does the MsgBox statement display?

Sub MySub(VarA As Long, ParamArray VarB() As Variant)
MsgBox VarB(0)
End Sub
Sub ShowValue()
Call MySub(10, "First arg", 2, 3.1416)
End Sub

Q5. What object is needed to put a userform module in a VBA project?

Q6. What is the output?

Sub UseSum()
Dim TestArray() As Integer, Total As Integer
ReDim TestArray(1)
TestArray(1) = 6
ReDim TestArray(2)
TestArray(2) = 3
Total = WorksheetFunction.Sum(TestArray)
End Sub

Q7. The Driver subroutine is declared by Sub Driver (Y). Which statement results in a compile error?

Q8. You have several variables to display on a user form, and there are too many variables to display at once. Which control best enables the user to see all the variables?

Q9. Below is a function named SquareIt. Which version of the subroutine named Area results in a compile error?

Function SquareIt(ByRef Basis As Integer) As Long
SquareIt = Basis ^ 2
End Function
Dim Result As Long, Side As Integer
Side = 5
Result = Squarelt(Side)
End Sub
Dim Result As Long, Side
Side = 5
Result = SquareIt(Cint(Side))
End Sub

Q10. EmailAddress() is an array. It is declared by Dim EmailAddress(10) As String, and option Base 1 is in effect. How many rows and columns are in EmailAddress()?

Q11. Which cell is selected if you run this code?

Range("E3:312").Range("B3").Select

Q12. Which variable name is valid in VBA?

Reference link

Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basic module: You must use a letter as the first character. You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name. Name can't exceed 255 characters in length.

Q13. Which is a valid definition of a user-defined data type?

Type CBC
Name As String
Next As String
End Type
Type CBC
Name As String
_Next As String
End Type
Type CBC
Name As String
@Option As String
End Type
Type CBC
Name As String
%For As String
End Type

Q14. What is one way to duplicate a user form from one project into a different project?

  1. Save and close the project with the existing user form.
  2. Click Insert > File.
  3. Browse to the location of the existing project.
  4. Right-click it and select the user-form you want to duplicate.
  1. Open the existing user form in Desing Mode.
  2. Right-click the form and select Copy.
  3. Switch to the other project.
  4. Right-click Module and select Paste.
  1. In the Project Explorer, right-click the user form and select Copy.
  2. Switch to the new project.
  3. Right-click UserForms and select Paste.
  1. Open the existing user form in Design Mode.
  2. Click File > Export File.
  3. Switch to the other project.
  4. Click File > Import File.

Q15. The recording of a macro in Word is likely to be an incomplete record of the user’s actions. Why?

Q16. Which statement should precede a subroutine’s error handler?

Q17. How many values can MyArray hold?

Option Base 0
Sub BuildArray()
Dim MyArray(5) As Integer

Q18. Which statement is true?

Q19. A declaration has a scope, which has three levels. What are they?

Q20. There are two references that must be selected in the Visual Basic Editor in order for any Visual Basic code to run in Excel. What are these two references?

Q21. Which action will cause your project to reset its variables?

Q22. Which keyboard shortcut causes VBE to locate the declaration of a procedure?

Q23. When you define a new class of object, where do you assign a name to it?

Q24. How does a class module indicate that it uses a particular interface?

Q25. What is needed for the contents of Module1 to be available to other modules in a VBA project, but not to any other VBA project?

Q26. When used with an array named MyArray, what is the preferred way to set the beginning and ending values of a loop control variable?

Q27. What is the value of Test3?

Enum TestEnum
    Test1
    Test2
    Test3
End Enum

Q28. Which statement declares an array?

reference

Q29. To use VBA code to maintain a different VBA project, you can make use of VBA’s extensibility. What is needed to enable extensibility?

Q30. How do you add a user form to a VBA project?

  1. Select the project in the Project window of the Visual Basic Editor
  2. Click the Design Mode button and select Insert Mode
  1. Select the project in the Project window of the Visual Basic Editor
  2. Click the Toolbox button and select UserForm
  1. Select the project in the Project window of the Visual Basic Editor
  2. Right-click the Run menu and select Customize
  1. Select the project in the Project window of the Visual Basic Editor
  2. Click Insert > UserForm

Q31. Explicit variable declaration is required. MyVar is declared at both the module and the procedure level. What is the value of MyVar after first AAA() and then BBB() are run?

Dim MyVar As String
Sub AAA()
Dim MyVar As String
MyVar = "Procedure AAA Scope"
End Sub
Sub BBB()
MyVar = "Procedure BBB Scope"
End Sub

Q32. Which code block from class modules returns a compile error?

Public Property Get HDL() As Double
HDL = pHDL
End Property
Public Property Let HDL(Value As Double)
pHDL = Value
End Property
Property Get HDL() As Double
HDL = Value
End Property
Property Let HDL(Value As Double)
pHDL = Value
End Property
Public Property Get HDL() As Double
HDL = Value
End Property
Public Property Let HDL(Value As Double)
pHDL = Value
End Property
Public Property Get HDL() As Single
HDL = pHDL
End Property
Public Property Let HDL(Value As Double)
pHDL = Value
End Property

Q33. If VBA code declares FileCount as a constant rather than a variable, the code tends to run faster. Why is this?

Q34. A VBA project must declare four classes. How many class modules are needed?

Q35. What does this code display?

Sub MakeErrors()
Dim Y As Variant, Z As Variant
On Error Resume Next
Y = 1 / 0
MsgBox "Y = " & Y
On Error GoTo 0
Z - (0 - 3) ^ 0.5
MsgBox "Z = " & Z
End Sub

Q36. The VBA code block shown in the following four options runs when UserForm1’s CommandButton1 button is clicked. Which block of code leaves UserForm1 loaded but not visible until the FoundErrors function has checked it, and then enables processing to continue if no errors are found?

Private Sub CommandButton1_Click()
If FoundErrors(Me) Then _
Me.Show
End Sub
Private Sub CommandButton1_Click()
If Not FoundErrors(UserForm1) Then _
Unload UserForm1
End Sub
Private Sub CommandButton1_Click()
Me.Hide
Do While FoundErrors(Me)
Me.Show
Loop
End Sub
Private Sub CommandButton1_Click()
Do While FoundErrors(UserForm1)
UserForm1.show
Loop
End Sub

The first requirement is to make UserForm1 loaded but not visible, therefore, we need Me.Hide, Me in here referring to UserForm1

Q37. Which is the correct way to structure a With block?

With Selection
&TypeText Text:="8/24/2019"
&TypeParagraph
&TypeText Text:="1161 Alamosa Drive"
End With
With Selection
.TypeText Text:="8/24/2019"
.TypeParagraph
.TypeText Text:="1161 Alamosa Drive"
End With
With Selection
TypeText Text:="8/24/2019"
TypeParagraph
TypeText Text:="1161 Alamosa Drive"
End With
With Selection:
&TypeText Text:="8/24/2019"
&TypeParagraph
&TypeText Text:="1161 Alamosa Drive"
End With

reference

Q38. Why does this code generate a “Subscript out of range” error?

Sub Example()
    Dim MyArr() As Variant
    ReDim MyArr(3, 4)
    'some code
    ReDim Preserve MyArr(4, 4)
End Sub

Q39. Which subroutine declaration does not cause a compile error?

Q40. How can a user enter data on a worksheet or document, or switch windows, while UserForm1 is displayed on the screen?

Q41. SubA passes MyVar to SubB. How can you ensure that MyVar has its original value when control returns to SubA?

Q42. Which procedure declaration is syntactically correct?

Sub MySub(VarA As String, Optional VarB _
As Variant, Optional VarC As Long)
Sub MySub(VarA As String, Optional VarB _
As Variant, VarC As Long)
Sub MySub(Optional VarA As String, Optional VarB _
As Variant, VarC as Long)
Sub MySub(OPtional VarA As String, VarB _
As Variant, Optional VarC as Long)

Q43. What are the two principal kinds of procedures in VBA?

Q44. Which code block compiles without error?

Q45. What is used in the Immediate window to display the current value of the variable CountValues?

Q46. At which level can you declare a variable in this way: Private TopSecret As String?

Q47. How can a user enter data on a worksheet or document, or switch windows, while UserForm1 is displayed on the screen?

Q48. SubA passes MyVar to SubB. How can you ensure that MyVar has its original value when control returns to SubA?

Q49. Arrays cannot be resized more than once.

Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4)
End Sub Sub Example() Dim MyArr() As Variant ReDim MyArr(3, 4) 'some code ReDim Preserve MyArr(4, 4) End Sub

Q50. Which block of code ends with the variable i equal to 5 and the variable X equal to 10?

Do
X = X + 1
i = i + 1
Loop Until i < 5
End Sub
Sub Loopi()
Dim X As Integer, i As Integer
For i = 1 To 5
X = X + 1
Next I
End Sub
Sub Loopi()
Dim X As Integer, i As Integer
Do Until i < 5
X = X + 1
i = i + 1
Loop
End Sub
Sub Loopi()
Dim X As Integer, i As Integer
Do
X = X + 1
i = i + 1
Loop While i < 5
End Sub

Q51. How does a class module indicate that it uses a particular interface?

Q52. Which part of the VBE can help you explore VBA syntax?

Q53. This code is trying to establish a new collection consisting of employee names and numbers. Assoc is a class. What statement is missing from the code?

Dim Associates As Collection, Assoc As CAssoc, i As Byte
For i = 1 To 200
    Set Assoc = New CAssoc
    Assoc.Name = Cells(i,1)
    Assoc.Number = Cells(i,2)
    Associates.Add Assoc
Next i

Q54. What is the standard term for a variable or value that is passed from one subroutine or function to another?

Q55. What is the standard term for a variable or value that is passed from one subroutine or function to another?

Q56. Where is the event procedure named Worksheet_Change found?

Q57. You are building an event procedure for a worksheet, and you edit the argument list in the event procedure’s Sub statement. What happens when the event procedure runs?

Q58. Based on this code, which procedure calls the subroutine SumCosts correctly?

Sub Sumosts(AcctName As String, Amount As Long)
    Range("A1") = AcctName
End Sub

Source

Q59. You want to declare an object that describes cars so that your VBA code can apply tests such as the following. What keyword do you use to declare Cars?

If Cars(1).Make="Ford" And Cars (1).MPG > 20
    Then Cars(1).Selected = True

Q60. What is the purpose of the .Range(“A1:E5”).Select portion of this statement?

ActiveCell.Offset(3,4).Range("A1:E5").Select

Q61. In Excel, what is the effect of the two statements below?

Range("b3:f5, c4:d9").Select
    	Range("b3:f5", "c4:d9").Select

Q62. What does VBA stand for in the context of programming?