Table of Contents
Introduction to VBA for Excel
VBA stands for Visual Basic for Applications. It is a custom version of the Visual Basic programming language that has powered Microsoft Excel’s macros since the mid-1990s. The programming interface of MS Excel will let you,
- Create and Execute Macros (explained in the next section). Anything that the user can do in Excel from the user interface can be done by writing code in VBA for Excel.
- Create User Defined Functions (UDFs).
- Integrate Excel with other applications such as Microsoft Word, PowerPoint, Outlook, Notepad, etc.
What is a Macro ?
Macros are codes written in VBA (Visual Basic for Applications), or recorded in MS Excel (or other MS applications) which helps to reduce the manual effort required for a job. Macros save your time and headaches by automating common, repetitive tasks. They reduce the possibility of human error that increases with many, repetitive keystrokes and tasks. The most important feature of an Excel macro is, it can be saved for future use, shared among multiple users.
In a layman’s language, a macro is a recording of your routine steps in Excel that you can replay using a single button
The best part is You don’t have to be a programmer or know Visual Basic Applications (VBA) to use Macros. You just need to copy the codes shared here and hit the run button to execute them. Save the file as a Macro enabled workbook for future use.
How to use the codes shared here?
- Step 1: Copy the Code.
- Step 2: Go to the Developer tab of the Excel ribbon and Click on Visual Basic to activate the Visual Basic Editor of Excel. ‘ALT + F11’ is the keyboard shortcut for the Visual Basic Editor.
- Step 3: Right click on the tree view and select Insert to insert a new ‘Module’.
- Step 4: Paste the copied code into the newly inserted module.
- Step 5: Close the VB editor and Click on Macros in the Developer Tab. You will get a dialogue box with the list of Macros ready for execution. Click on the Run button to execute the macro.
Ready to use Macros
Things to remember while using Macros
- By default, the tab for developers is not displayed in excel. If you can’t see the Developer tab, use the quick access toolbar to activate it.
- By default, Macros are disabled in excel. To execute macros, you will need to enable running macros.
- We cannot Undo an action performed using Macro. Make sure that you have a backup of the data before executing the macro.
- To save macros in a workbook, you must save your workbook in a macro-enabled format *.xlsm
- Always fill in the description of the macro when creating one. This will help you understand your own work if you have to revisit it weeks or months later.