0% found this document useful (0 votes)
29 views

QB of Section II Shared With Students of 2325 For Practice

The document contains questions and answers related to VBA and Excel. It covers topics like loops, variables, arrays, functions, macros and more. There are over 60 questions in total with answers to help learn VBA concepts and syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

QB of Section II Shared With Students of 2325 For Practice

The document contains questions and answers related to VBA and Excel. It covers topics like loops, variables, arrays, functions, macros and more. There are over 60 questions in total with answers to help learn VBA concepts and syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Question

Sr.No. Answer1
1 Correct syntax to create a WHILE
LOOP
WHILE...WHILE END
2 Cells().Value and Range().value

works same
3 What is output of following VBA
macro,
Sub XYZ()
Range("A1").Value = "Hello"
End Sub

Error Message
4 __________ function enables to
change value of a cell
range("A1").Value
5 The variables that does not change
the value during execution of
program is __________ Numeric
6 Which of the following is not
looping statement It Then Goto
7 Is it obligatory to declare
variables? Only if Require
Variable Declaration is
enabled
8 What is output of following VBA
macro,
Sub XYZ()
Dim i, a As Integer
a=1
For i = 1 To Range("A1").Value
Cells(i, 4).Value = a
a=a+2
Next i
End Sub

Prints 1 to value in C1
from A2
9 The default property for a text box
control is __________
Text
10 Define String Varable in VBA

Dim J as String
11 Which of the following is not a
valid data type in excel Number
12 R[-2]C will indicate
_______________ Cell Two rows above and
same column the Active
Cell
13 The Properties window plays an
important role in the development To change how objects
of Visual Basic applications. It is look and feel
14 mainly used
Which of following is incorrect, Macros allow one to
add significant power
to Excel.
15 What are the data types in VBA?

Boolean
16 A __________ variable is one that
is declared inside a procedure.
global
17 The default datatype for VB is
___________
Integer
18 In visual basic the declaration of
variables is done by _____ key
word.
int
19 Comments put in cells are called

Smart tip
20 R3C2 indicates ________ cell

C2
21 Which programming language
does VBA is based on?
Visual Borland
22 Define Integer Array in VBA

Dim IntArr() As Integer


23 _________ is the process of
finding and removing errors.
Checking
24 __________ function enables to
display popup message
MsgBox
25 What is output of following VBA
macro,
Sub XYZ()
MsgBox ("Hello !! This is Excel
Macro Test.")
End Sub

Error Message
26 What is a Macro?

It is an Excel Formula
27 A VBA unit is called a _____

Subroutine
28 ___________ referncing indicates
columns also in number
1111
29 __________ do not return a value.

Sub procedure
30 Correct syntax to create IF
statement If << condition >> Then
<< statements >> Else
<< statements >> End
If
31 Correct syntax to create a DO
WHILE LOOP Do While << condition
>> [statement ....]
Loop
32 Resize property is
used______________ Increase number of
rows in sheet
33 _________ is a built in function to
return lower bound of an array.
Lbound()
34 Define String Array in VBA

Dim Str() as String


35 VBA is:
a Microsoft
programming
language used to
extend Excel functions
36 When we don’t declare fixed
number of elements in the arrary,
it is called Fixed
________________________
37 What is output of following VBA
macro,
Sub XYZ()
Dim i As Integer
For i = 1 To Range("A1").Value
Cells(i, 3).Value = i
Next i
End Sub

Prints 1 to value in A1
from C1
38 Correct syntax to create a FOR
LOOP
FOR..LOOP
39 _________ is used for finding out
the properties of selected control
in User form
Form layout window
40 To input the formula with R1C1
referencing, we use
_____________ method
Formula
41 ________ loop repeats a group of
statements for each item in a
collection of objects or for each
element of an array.
While loop
42 The function procedures are
___________ by default.
public
43 What is output of following VBA
macro,
Sub XYZ()
Range("A1").Value =
ActiveCell.Address
MsgBox ActiveCell.Address
End Sub
Puts in A1 and
Messages the address
of active cell
44 What is output of following VBA
macro,
Sub XYZ()
Dim temp As Double
temp = Range("A4").Value
Range("A4").Value =
Range("B4").Value
Range("B4").Value = temp
End Sub

Error Message
45 In Visual Basic, a variable name
cannot be more than __________
characters. 255
46 OffSet property is
used______________
Increase the range
47 Which of the following VBA
windows shows the code of the
active object? Explorer Window
48 When the user clicks a button,
_________ is triggered.
an event
49 The ______ is a tool used for both
the Input and output purpose.
label
50 The output of- OFFSET(A1,4,3,2,3)
is_________
The Value in Cell G7
51 The _________ allows direct exit
from a For loop, Do loop, Sub
procedure, or Function procedure. Break
52 What is the shortcut key to open
VBA editor, in excel?
ALT+F9
53 MDI stands for _________
Multiple Document
Interface.
54 __________ statement enables us
to trap runtime error.
Error
55 Which of the following VBA
windows shows the code of the
active object?
Explorer Window
56 When the user clicks a button,
_________ is triggered.
an event
57 We can use ________ statement
to search last row of data =Cells(Rows.count,1).E
nd(xlUp).Row
58 Which of the following refers to
computer code, in VBA, that
performs some action on or with Excel function
59 objects?
Visual Basic is a tool that allows
you to develop application in
__________ Real time
60 __________ character use to put
comment in VBA
"
61 Define Integer Varable in VBA Dim i As Integer
62 I want that Excel should mandate
me to declare every variable I use No, such facility is not
in my program with DIM available
statement. How do I do it?
63 what is the output of
"ActiveCell.Value =
ActiveCell.Offset(-1, 0).Value + 1"
statement Will fetch value of
previous column and
same row of active
cell, add in in it and
put it in active cell
64 Which variable is private and
which is public? Dim B
As String
Sub DeclareVar()
Dim A As String
A = "Product "
B = "ID"
End Sub
Sub PrintVar()
Range("A1").Value = A
Range("B1").Value = B
End Sub

B is Public , A is Local
65 User Defined Function returns of function name
variable _________________

66 range("A1:C3").offset(2,3).select D3:F5
statement will select range
____________.
67 To retain the data in an dynamic
array __________ ketword is used
with ReDim statement Retain
68 Which code block will check Dim Num As Integer
whether the number entered in A1 Num =
is ODD or EVEN and syntactically Range("A1").Value
right? If Num Mod 2 = 0
Then
Range("A2").Value =
"Even"
Else
Range("A2").Value =
"Odd"
End If

69 When user selects any sheet Workbook's Activate


_________ event occurs? Event

70 Which of the following is not a Workbooks


collection?

71 What will following statement do? Will take cursor to


upmost cell of the row
cells(rows.Count,1).end(xlUp).row
72 Dim Arr() as String statement Declare Static array
will_____________ names Arr

73 ___________ is the default Lower 0


bound in the VBA Arrays?

74 Difference between Both are similar


Worksheets.Count and
Sheets.count is
75 _________________
________________________
Statement defines arrays with
Lower Bound 1 Option Explicit
76 In VBA Model the sequence of
collection is
Workbooks-
>Worksheets-
>Application->Range
77 What will output of following Validates the data in
code? Private column B and restricts
Sub Worksheet_Change(ByVal user to enter only
Target As Range) Numbers, gives
If Target.Column = 2 Then message if user enters
If Not IsNumeric(Target.Value) other data than
Then Number
MsgBox "Dont enter other
than numbers"
Target.Value = ""
End If
End If
End Sub

78 What will be the output? Colors cells in coulmn


Sub Test2() 1 with Red
Dim i As Integer
Dim LastRow As Integer
Worksheets(2).Activate
LastRow = Cells(Rows.Count,
1).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, 1) = Cells(2, 2) Then
Cells(i, 1).Interior.Color =
vbRed
End If
Next i
End Sub
79 what will be values in "a" Array a(1)= "XYZ",
after exceuting the code? a(2)=41.25, a(3)=22,
Public Sub a(4)= 4, a(5)=5, a(6)=6,
Constant_demo_Click() a(7)=5
Dim a() As Variant
Dim i As Integer
i=0
ReDim a(3)
a(1) = "XYZ"
a(2) = 41.25
a(3) = 22
'-------------------------------
ReDim a(7)
For i = 4 To 7
a(i) = i
Next
End Sub

80 Which rows or columns following Will delete Row which


code will delete and with which has no value in column
Condition? A
Sub DeleteRow()
Dim LastRow As Long, i As Long
LastRow = Cells(Rows.Count,
1).End(xlUp).Row
For i = LastRow To 1 Step -1
If IsEmpty(Cells(i, 1)) = True
Then
Cells(i, 1).EntireRow.Delete
End If
Next i
End Sub
81 Sub ForEachLoop() Highlights A1 of
Dim sh As Worksheet ActiveSheet with Red
For Each sh In Worksheets Color
sh.Cells(1, 1) = "HI"
sh.Cells(1, 1).Font.Color = vbRed

Next sh
End Sub

82 We can use Public statement after 1


Option Explicit statement
Answer2 Answer3

WHILE…..END WHILE...WEND

refere to single cell and refere to


marginal difference range

Messages "Hello" Puts "Hello" in A1

change("A1").Value update("A1").value

String Constant

Do Until Do While

It is not, Excel declares them


It is obligatory in all automatically according to the
circumstances value added.
Prints total numbers mentioned
in A1 starting from C1, each by
Error Message adding 2 in previous

Enable Multiline

Dim J as Text Dim J as text.value

Character Label
Two Columns left and
same row of the active Two Columns right and same row of
cell the active cell
When opening To allow the developer to
programs stored on graphically design program
aThey
hardare
drive
small components
programs that can
be called from a You can create functions or
spreadsheet. subroutines.

Byte Currency

local external
Decimal Variant

dim static

Cell tip Web tip

B3 B2

Visual Base Variable Base

Dim IntArr As
Integer Dim IntArr As Integer Array

Compiling Debugging

MessageBox MessageBox()

Displays
messagebox with Types value in message in cell
message
It is a shortcut A1 of active sheet
which runs a
recorded or written It is a built-in process included in
process. Excel.
Routine Macro

AAAA R1C1

Function procedure Property procedures

If << condition >>


Then << statements If << condition >> Then <<
>> Else << statements >> Else If <<
statements >> End statements >> End If

Do While <<
condition >> Do While << condition >>
[statement ....] End [statement ....] End Loop

Increase the active Increase number of columns in


range size sheet

LRbound() Lowbound()

Dim Str as String Dim Str as String Array

a statistical tool
developed by
Microsoft for an open-source programming
financial analysts environment

Preserve Dynamic array


Error Message Prints 1 to value in C1 from A1

FOR..END FOR FOR...NEXT

Code editor window Object browser

R1C1 Formula R1C1

Do Until loop Do while loop

private protected
Puts in A1 the
address of active Messages the address of active
cell cell

Deletes value in B4 Exchanges values of A4 and B4

300 355

Deactivate the Set the values collectively to


selected rage selected range

Properties window Immediate window

a method a setting

Text box Combo box


The function will
return a #VALUE
error as it has
invalid parameters Range D5:F6

Exit Exit for

ALT+F8 ALT+F11
Multiple Design Manipulated Document
Interface. Interface.

On Error On runtime Error

Properties window Immediate window

a method a setting
=Cells(Columns.cou
nt,1).End(xlUp).Colu =Cells(Rows.count,1).End(xlUp).
mn Column

Sub-procedure Primary key

Graphical User
Interface Character User Interface

# '
Dim i As Int Dim i As Integer.value

Use OPTION
EXPLICIT statement Use OPTION BASE 1 statement
Will fetch value of
previous row and
same column of Will fetch value of previous row
active cell, add in in and previous column of active
it and put it in cell, add in in it and put it in
active cell active cell

A is Public , B is
Local Both are Public
mentioned after mentioned in the Return
function name statement

A1:C2 A1:B3

Continue Occupy
Dim Num As Integer Dim Num As Integer
Num = Num = Cells("A1").Value
Range(A1).Value If Num Mod 2 = 0 Then
If Num Mod 2 = 0 Cells("A2").Value = "Even"
Then Else
Range(A2).Value Cells("A2").Value = "Odd"
= "Even" End If
Else
Range(A2).Value
= "Odd"
End If

Worksheet's Workbook's Open Event


Activate Event

Workbook Worksheets

Will take cursor to Will take cursor to last cell of the


upmost cell of the range
range
Declare Dynamic Declare Arr variable having
array named Arr Variant data type

1 -1

Worksheets.count Worksheets.count returns


returns number of number of only sheets and
all types of sheets Sheets.count retruns number of
and Sheets.count all types of sheets

Option Base One There is no such statement


Application-
>Workbooks-
>Worksheets- Application->Worksheets-
>Range >Workbooks->Range
Validates the data Error
in column B and
restricts user to
enter only Text,
gives message if
user enters other
data than Text

Checks data in each Error


cell of Column 1 and
colors it with Red if
it contain Data
mentioned in Cell
B2
a(1)= Empty, a(1)= Empty, a(2)=Empty,
a(2)=Empty, a(3)=Empty, a(4)= 4, a(5)=5,
a(3)=Empty, a(4)= a(6)=6, a(7)=7
Empty, a(5)=5,
a(6)=6, a(7)=6

Will delete columns Will delete columns and rows


which has no value which has no value in either in
in row 1 column A or in row 2
Highlights A1 of Highlights A1 of all sheets in
Sheet1 with Red workbook
Color

0 Statement has no relevance


Answe
Answer4 r5 CorrectDifficul Marks CO BL

WHILEWEND…..........ST
OP 3 CO4(100)

3 CO5(100)

Messages and Puts in


A1 "Hello" 2 CO6(100)

1 CO5(100)

Date 3 CO5(100)

For Next 1 CO5(100)

3 CO4(100)
Will go in infinite loop 3 CO6(100)

Password char 1 CO4(100)

1 CO4(100)

Date/time 5 CO4(100)

Two rows below and same


column the Activerelated
To set program Cell 1 CO6(100)
options like Program
Name, Program
Location, etc 1 CO4(100)
If you want to get fancy, None
you can add a user of
interface as well. these. 5 CO4(100)

All of
String these 5 CO4(100)

project 2 CO4(100)
String 3 CO4(100)

declare 2 CO4(100)

Soft tip 2 CO4(100)

C3 2 CO6(100)

Visual Basic 4 CO4(100)

1 CO5(100)

Quick watch 3 CO5(100)

1 CO5(100)

Types value in message


on active user form 2 CO6(100)

2 CO4(100)
Program 3 CO4(100)

C1R1 3 CO5(100)

Module Procedure 1 CO5(100)

1 CO5(100)

1 CO5(100)

Increase number of
sheets in the workbook 2 CO5(100)

LB() 1 CO5(100)

1 CO5(100)

a Microsoft
programming
environment that
replaces Excel 1 CO4(100)

Multidimensional 3 CO4(100)
Will go in infinite loop 1 CO6(100)

FORNEXT….........STOP 3 CO5(100)

Properties window 4 CO4(100)

No such formula
available 3 CO5(100)

For each loop 4 CO5(100)

Friend 1 CO4(100)
Error 3 CO6(100)

Deletes value in A4 3 CO6(100)

to move or refer to a400 1 CO4(100)


reference skipping a
particular number of
rows and columns 4 CO5(100)

Code window 4 CO4(100)

a property 1 CO5(100)

command button 2 CO5(100)


The function will return
a #VALUE error as
incomplete data is
provided to the offset
function 3 CO5(100)

Exit Do 2 CO5(100)

ALT+F10 3 CO4(100)

Menu Design Interface. 1 CO4(100)

Error In 2 CO4(100)

Code window 4 CO4(100)

a property 1 CO5(100)

=Cells(Columns.count,1)
.End(xlUp).Row 1 CO5(100)

Integrity constrain 2 CO4(100)

Text User Interface 2 CO4(100)

+ 3 CO4(100)
1 CO5(100)
VBA by dafualt
mandates it. No need to
do anything 2 CO5(100)
Error 2 CO6(100)

Both are Private 1 CO6(100)


mentioned in the Exit 1 1 CO5(100)1
statement

C4:E6

1 CO5(100)

Preserve 4 CO5(100 4
Dim Num As Integer
Num =
Range("A1").Value
If Num Mod 2 = 0 Then
Range("A2").Value =
"Even"
Else if
Range("A2").Value =
"Odd"
End If

CO6(100)
Worksheet's Open
Event
CO5(100)
Names

CO5(100)
Will return lastrow in
the column which has
data 3 CO5(100)
Error

2 CO5(100)
Programer defined 1

CO5(100)
Irrelevant statement

3 CO5(100)

Option Base 1 4 CO5(100)


Application->Range-
>Worksheets-
>Workbooks 2 CO4(100)
Nothing will happen 1

CO6(100)
Checks data in each cell 2
of Column 2 and colors
it with Red if it contain
Data mentioned in Cell
A2

CO6(100)
Error 3

CO6(100)
Delete all values in 1
Column B

CO6(100)
Highlights A1 of Last 3
Sheet with Red Color

CO6(100)
Neighther True not 1
False
CO4(100)

You might also like