VBA

HOW DO YOU STOP RECORDING A MACRO?
Step 1: Go To Developer tab from the main ribbon of Excel window.
Step 2: Click on ‘Stop Recording’ command button to stop from the recording macro.

HOW DO YOU RUN A MACRO IN EXCEL?
Press the “play” button on the macro toolbar.
Or use the keyboard shortcut “Alt+F8” to open the macro dialog box, where you can then select the macro you want to run.

WHAT ARE THE STEPS TO FOLLOW BEFORE BEGINNING WITH MACROS?
Go to File > Options > Customise Ribbon. Then, in the Customise the Ribbon section, under Main Tabs, check the Developer check box, and press OK.

HOW DO YOU SAVE AN EXCEL MACRO?
When you write a macro, it is saved automatically in the workbook where you wrote it; there is no need to save it separately. However, you must save the workbook in macro format (.xlsm). When you try to save a workbook with a macro in another format, Excel warns you.

HOW DO YOU RUN A MACRO?
You can select a macro from the list and run it. On the Developer tab, there’s a button called macros that, when clicked, displays a dialogue box with a list of macros from all open workbooks.

HOW TO ASSIGN VALUES TO AN ARRAY?
We can assign values to an array by:
‘Declare an array variable
Dim aValue (2) As Integer
aValue(0)=”first”
aValue(1)= “Second”
aValue(2)= “Third”
‘Or
Dim aValue () As Integer={” first “,”Second”,”Third”}

HOW TO ADD USERFROM TO A VBA PROJECT?
Step 1: In the VBA Editor window, navigate to the Insert menu.
Step 2: Select ‘UserForm to Add to Project’. In the Project Explorer, you can now see the newly added UserForm. The default UserForm name is ‘UserForm1’. You can change the name of the UserForm by using properties.

WHAT ARE VARIABLES IN EXCEL VBA USED FOR?
Variables are used to store data that can be referenced throughout the code. Text strings, numbers, and objects are examples of this. This information can be easily accessed and used later in the code by storing it in a variable. This makes coding much simpler and more efficient.

HOW CAN YOU STOP A VBA SCRIPT WHEN IT GOES INTO THE INFINITE LOOP?
By Ctrl+ Pause Break, key one can discontinue VBA script when it goes into an infinite loop

EXPLAIN HOW TO DEBUG A VBA CODE?
To debug a VBA code, follow the steps
Using Breakpoints (F9)
Step by step execution (F8)
Print & Immediate Window and Watch the window

HOW DOES “REFERENCE COUNTING” WORK IN VBA?
When a variable exits scope in VBA, the reference counter on the reference object is decremented. The reference counter is incremented when you assign the object reference to another variable. When your reference count reaches zero, the event is terminated.

WHY ARE USERFORMS USED AND HOW ?
For complex user input, userforms should be used. When using non-text as an input in an application, it is recommended to use Userforms rather than input boxes. When we use Userforms, a user can provide input an unlimited number of times, which is not the case when we use input boxes. This is accessed via the insert menu in your VBA editor, where you can then insert your code.

WHAT IS THE COMMENT STYLE IN VBA?
Comments are used to document the programme logic and user information so that future programmers can work seamlessly on the same code. In VBA, there are primarily two ways to represent comments.
1.) Any statement that begins with a single quotation mark is considered a comment.
2.) Alternatively, you can use the statement REM instead of the single quotation mark (‘).

EXPLAIN WHAT IS VBA OR VISUAL BASIC FOR APPLICATIONS?
VBA stands for Visual Basic for Applications; it is an event driven programming language developed by Microsoft. It is predominantly used with Microsoft office applications like MS-word, MS-Access, and MS-Excel.

WHERE CAN YOU WRITE YOUR VBA PROGRAM FOR MACRO?
Module is the place where you can write VBA program for Macro, to insert a Module navigate to Insert ->Module

HOW CAN YOU PASS ARGUMENTS TO VBA FUNCTIONS?
ByVal: If an argument is supplied to a procedure by Value rather than by the argument itself, then the procedure will only get the value passed, and any modifications made to the argument inside the procedure will be lost when the procedure exits.
ByRef: The actual address of the argument is supplied to the procedure when the argument is passed by reference. When the process is ended, any modifications made to the argument inside it will be recalled.