1) What is VBA?
VBA stands for Visual Basic Application. It is an event-driven programming language. It is mainly used with Microsoft Office applications such as MS -Excel, MS-Word and MS-Access.
2) Who is the developer of VBA?
Microsoft is the developer of VBA.
3) What are the two ways to denote comments in VBA?
In VBA, there are two ways to denote comments:
- Single Qutoe(‘) : Example ‘Hello World
- Start with REM keyword : Example REM Hello world
4) What is the use of MsgBox function?
MsgBox function is used to display a message box.
Sytntax:
MsgBox(prompt[,buttons][,title][,helpfile,context])
5) How can we create user define functions in VBA?
We can create user define functions by using following syntax:
Function Functionname(parameter-list)
statement 1
statement 2
statement 3
.......
statement n
End Function
6) What is the use of InputBox function in VBA?
In VBA, InputBox function is used to take input value.
InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
7) What is the rule of naming a variable?
There are following rule of naming variable:
- We should use a letter as the first character.
- We should use a space , period(.) , exclamation mark (!) or the characters @, &,$,#.
- Name can’t exceed 225 characters in length.
- We can’t use Visual Basic the variable before using them
8) How to declare the variable in VBA?
In VBA,
Dim keyword is used to declare the variable.
Example:
9) What are the types of operator in VBA?
There are following operators in VBA:
- Arithmetic Operators
- Comparison Operators
- Logical (or Relational) Operators
- Concatenation Operators
10) What are the loops in VBA?
There following loops in VBA:
- for loop
- for ..each loop
- while..wend loop
- do..while loops
- do..until loops
11) What are the predefine String functions in VBA?
In VBA, predefine string functions are:
String functions |
Description |
Lcase |
It returns the lower case of the specified string. |
Ucase |
It returns the upper case of the specified string. |
Ltrim |
It returns a string after removing the space on the left side of the specified string. |
Len |
It returns the length of the given string. |
Replace |
It returns a string after after replacing a string with another string. |
12) How can we declare an Array?
We can declare an array by using given code:
'Method 1 : Using Dim
Dim arr1() 'Without Size
'Method 2 : Mentioning the Size
Dim arr2(5) 'Declared with size of 5
'Method 3 : using 'Array' Parameter
Dim arr3
arr3 = Array("apple","Orange","Grapes")
13) What is the use of ReDim statement in VBA?
In VBA, ReDim statement is used to declare dynamic-array variable and allocate or reallocate storage space.
Syntax:
ReDim [Preserve] varname(subscripts) [, varname(subscripts)]
14) What are Array methods in VBA?
In VBA, There are given Array methods:
Array Method |
Description |
LBound |
It returns an integer that corresponds to the smallest subscript of the given array. |
UBound |
It returns an integer that corresponds to the largest subscript of the given arrays. |
Join |
It returns a string that contains a specified number of values. |
Erase |
It recovers the allocated memory for the array variables. |
IsArray |
It returns a Boolean value that indicates whether or not the input variable is an array. |
15) How many types of error in VBA?
In VBA, there are three types of error that are given below:
- Syntax Errors
- Runtime Errors
- Logical Errors