Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
VBA is an abbreviated form for Visual Basic for Applications. Excel VBA is Microsoft's language for Excel and other Microsoft Office programs. The Office suite programs all share a standard programming language.VBA helps develop windows API, automation processes, and user-defined functions. VBA also allows us to manipulate the user interface features of the host applications.
Excel VBA is a subset of Visual Basic 6.0 BASIC. In this blog, we will discuss about Excel VBA in detail.
While users cannot directly manipulate the leading Excel software through VBA, they can achieve the art of making macros to utilize their time in Excel. There are two methods to create Excel macros.
The first way is to make use of the Macro Recorder. After activating the recorder, Excel will record all the user's steps and save it as a "procedure" called a macro. When the user quits the recorder, this macro gets saved and can be assigned to a button that will run the same process when clicked. This method is simple and requires no previous knowledge of the VBA code. This method will work for everyday operations.
However, the decline of this method is that it is not very user-friendly, and the macro will mimic the user's input exactly. By default, recorder macros use absolute referencing in place of relative referencing. IKt means that macros made in this way are complex to use with variables and "smart" processes.
The second and more robust method of creating an Excel macro is to code using VBA.
Personal and Business Applications of Excel VBA
Personal use: We can use it for basic macros that will automate most of our routine tasks. Examples: Time management, Task management, calculating daily expense data.
Business use: We can create robust programs powered by Excel VBA. Examples: For maintaining complex trading, generating financial ratios, and risk-management models.
Introduction to Visual Basic for Applications
Variables
In the earlier days of our education, we learned about algebra. Find (x+2y), where x=1 and y=2. Here, x and y are variables. They can also be changed to say 3 and 3, respectively. Variables are memory locations. In Excel VBA, we will be required to declare variables.
Rules for creating variables
🎯 Reserved words are prohibited: Reserved words are words that have special meaning in Excel VBA, and we cannot use them as variable names.
🎯 Variable names cannot have spaces: We cannot define a variable as my number; we can use myNumber or my_number.
🎯 Use descriptive names: We should use descriptive names such as subtotal, quantity, price, etc. These names help to make our Excel VBA code easy to read.
Arithmetic Operators
The rules BODMAS is applied, so do not forget to apply them when working with arithmetic operators; similarly, in excel, we can use:
Operators
Use
+
Addition
-
Subtraction
*
Multiplication
/
Division
Logical Operators
The concept of logical operators is applied when working with Excel VBA. These include:
OR
NOT
If statement
TRUE
FALSE
AND
Where to Code Excel VBA?
To access the VBA window, press Alt + F11 inside any Office program. When done correctly, this will open a window with the top left containing a tree structure, the bottom left having the properties, and the bottom center containing a debug pane. This may seem overwhelming at first sight, but in reality, it's simpler.
How to use VBA in Excel
In this blog, we will look at how to use Excel VBA with the help of the following steps:
🕵️♀️Step 1: Open the VBA editor. In the VBA editor, in the main menu under the developer tab, select the "Visual Basic" icon.
🕵️♀️Step 2: Select the Excel sheet and click on the ThisWordbook option. After clicking the worksheet will open a VBA editor on the right-hand side. It will display a white text box.
🕵️♀️Step 3: Type the text we want to display in the MsgBox. For writing VBA program,
Start with writing "sub" and then our "program name" (Ninja)
And then type the text we want to display in the MsgBox(Coding Ninjas is the Best platform)
End the program by End Sub
🕵️♀️Step 4: Click on the run button on top of the editor
🕵️♀️Step 5: Select the sheet and Press the "Run" button.
🕵️♀️Step 6: Display the msg in MsgBox
After clicking on the Run button, the program will get implemented. It will show the msg in MsgBox.
Frequently Asked Questions
Write the full form of VBA.
Virtual Basic for Applications
Define Excel VBA.
Excel VBA is Microsoft's language for Excel and other Microsoft Office programs.
What is the need to use Excel VBA?
While users cannot directly manipulate the leading Excel software through VBA, they can achieve the art of making macros to utilize their time in Excel.
Where to code Excel VBA programs?
To access the VBA window, press Alt + F11 inside any Office program.
What language does Excel VBA use?
Excel VBA use Visual Basic 6.0 as its language which is built into many of the Microsoft Office applications.
Conclusion
In this article, we have discussed Excel VBA in detail. We started with the introduction and saw how to use Excel VBA, Personal and Business Applications of VBA in Excel, discussed briefly about Visual Basic for Applications, and examples of how to use VBA in Excel.