VBA Macro Interview Questions

• VBA stands for Visual Basic for Applications.
• VBA is Programming language available in MS Office Tools.
Data types helps to declare Variables with specific data, this helps to VBA to know the type of the data and assign the memory based on the DataType of the Variable.
1. Boolean
2. Byte
3. Currency
4. Date
5. Double
6. Integer
7. Long
8. Object
9. Single
10. String
11. Variant
Variant data type is default data type and it can hold any type of data. This will allocate maximum memory to hold the Varian Type. We use Variant data-type when we do know the type of the data or to accept the multiple data types in a single variable.
Arrays are type of variables allows to store multiple data values in one variable. It can contain multiple Dimensions like 2-dimensions, 3-dimensions,etc.
We can redefine the size of the array using REDIM statement. We use PARSE statement will to keep the previously stored data in the data.
Execution: Place the Cursor in a procedure and Press F5 to Execute
Step by Step Execution: Place the Cursor in a procedure and Press F8 to Execute the Program Step by Step
Toggle Breakpoints: Place the Cursor at the required statement and Press F9 to toggle the Breakpoint Printing in Immediate Window: Use Debug.Print to print in the Immediate Window
Executing in Immediate Window: Write your expression in the immediate window preceded by? (Question mark) and enter to execute the expression.
Press Esc Key to goto Debug Mode
Press Ctrl+ Pause Break Key to Skip from the Infinite execution.
ThisWorkbook refers to the workbook where code is being written while ActiveWorkbook refers to the workbook which is in active state with active window. In case of only one workbook open, ActiveWorkbook is same as ThisWorkbook.
Last Row in a column can be find using End(xlUp) and Last Column in a row can be find using End(xlToLeft). For e.g. Range("A1048576").End(xlUp).Row gives last used row of Column A.
:“Option Explicit” makes the declaration of variables mandatory. Line explicit function makes the compiler to determine all the variables that are not declared by the dim statement. This command diminishes the problem of type errors significantly. It is used in VBA because it deals with information rich application in which type errors are common. Before starting any, sub-procedures it can be used inside a module.
To find the last row in a column, the command used is End(xlUp) and to find last column in a row, the command used is End(xlToLeft).
A macro is nothing but set of instructions which are stored in Visual Basic module in a VBA Editor. It helps in automating common repetitive tasks on daily, weekly or monthly basis by running macro. Using macros, you can save lot of time, increase productivity and on time delivery to customers.
You can use the ‘Alt+F11’ key to go to VBA editor screen
Please find the different looping statements which are available in Excel VBA.
For…. Next loop, Do While…. Loop, Do until Loop, Do….Loop Until..,Do While Not…Loop, While…. Wend loop
Please find the below different types of error handling techniques.
1. On Error Resume Next
2. On Error GotoErr_Lbl
3. On Error Goto 0
You can save the workbook using following example. In the below example we are adding new workbook and then assigned it to object named Wkb. Finally we are saving workbook with using Save method of workbook object.
Sub Save_Workbook()
Dim WkbAs Workbook
Set Wkb = Workbooks.Add
End Sub
You can change the existing file name of workbook using the following example. In the below example we are adding new workbook and then assigned it to object named Wkb. Finally we are changing workbook name with using SaveAs method of workbook object.
Sub SaveAs_Workbook()
Dim WkbAs Workbook
Set Wkb = Workbooks.Add
ActiveWorkbook.SaveAs Filename:="C:\Test.xlsm"
End Sub
Please find the following statements to delete a file from the specified location.
Sub sbDelete_File()
Dim sFile As String
sFile = "C:\Test.xlsm"
'Set Object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Check File Exists or Not
If FSO.FileExists(sFile) Then
FSO.DeleteFilesFile, True
MsgBox "Deleted The File Successfully", vbInformation, "Done!"
MsgBox "Specified File Not Found", vbInformation, "Not Found!"
End If
End Sub
Note: Before deleting file from the specified location, we have to check whether file is exists or not in the specified location. In the above example we are using statement:’ FSO.FileExists(sFile)’ to check for the file.
You can copy a file from one location to another location in the following way.
Sub Copy_File()
Dim sFileName As String
Dim dFileName As String
sFileName = "D:\Test.xlsx" 'Source File Location Name
dFileName = "E:\Test.xlsx" 'Destination File Location Name
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFilesFileName, sFileName, True
End Sub
: You can move a file from one location to another location in the following way.
Sub Move_File()
Dim sFileName As String
Dim dFileName As String
sFileName = "D:\Test.xlsx" 'Source File Location Name
dFileName = "E:\Test.xlsx" 'Destination File Location Name
Name sFileNameAssFileName
End Sub
Msgbox is used to display the data or result
Inputbox is used to get the input from users.
HTML elements communicate to the browser how to render text. When surrounded by angular brackets <> they form HTML tags. For the most part, tags come in pairs and surround text.
Semantic HTML is a coding style where the tags embody what the text is meant to convey. In Semantic HTML, tags like < b> for bold, and for italic should not be used, reason being they just represent formatting, and provide no indication of meaning or structure. The semantically correct thing to do is use and . These tags will have the same bold and italic effects, while demonstrating meaning and structure (emphasis in this case).
The term DOCTYPE tells the browser which type of HTML is used on a webpage. In turn, the browsers use DOCTYPE to determine how to render a page. Failing to use DOCTYPE or using a wrong DOCTYPE may load your page in Quirks Mode. See example:
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>.
Perhaps the biggest issue is the poor browser support XHTML currently enjoys. Internet Explorer and a number of other user agents cannot parse XHTML as XML. Thus, it is not the extensible language it was promised to be. There are many other issues. Take your pick.
Quirks Mode is a default compatibility mode and may be different from browser to browser, which may result to a lack of consistency in appearance from browser to browser.
8 total. 4 pairs of tags. <HTML>
<TITLE>Simplest page ever!</TITLE>
To link an image, use < img> tags. You need specify the image in quotes using the source attribute, src in the opening tag. For hyperlinking, the anchor tag, < a>, is used and the link is specified in the href attribute. Text to be hyperlinked should be placed between the anchor tags. Little known fact: href stands for “hypertext reference.” When linking to an email, the href specification will be “mailto:send@here.com.” See examples below:
<img src=”HTMLrocks.jpg”></img>
<a href=”www.skilledup.com”>Skilledup</a>
<a href=”brad@skilledup.com”>Email Me</a>
It could be any number of things, but the most common mistakes are leaving out a tag bracket or quote missing for href, src, or alt text may be the issue. You should also verify the link itself.
Bulleted lists use the < ul> tag, which stands for “unordered,” whereas < ol> is used to create an ordered list.
Request a Call Back

Enter your Phone Number

Quick Contact

* Required Field
Training Course


Get A Free Quote / Need a Help ? Contact Us