Excel Macros or VBA Tutorial for Beginners (with Images)
This Introductory post/tutorial is for beginners who want to learn the basics of Excel Macros !
Before getting started with excel macros just two lines about Macros and VBA.
What is a Macro?
– A macro is a series of VBA commands and functions to perform a task.
What is VBA?
– VBA (Visual Basic for Applications) is a programming language that Microsoft Office (MS Excel, Word, Power Point, Access etc) applications uses.
An excel macro is a set of VBA commands and functions that automates the tasks you do in excel.
Set of VBA instructions = Macro = Automated task
The best part is you don’t have to know anything about VB or VBA to automate a task you do in excel or to create excel macros.
It is as simple as using a voice recorder in your mobile phone.
Click on start + record the task + click on stop = it’s done! Your macro is created!
Why don’t you try creating your first Excel Macro?
Let’s create a macro which fills Green color in your Excel cells. Follow the below steps.
Steps to create your first macro:
Step 1: Open a new Excel and go to the Developer tab then click on Record Macro from the Code section.
Step2: As soon as you click on Record Macro a pop-up window appears requesting you the following:
Macro name : GoGreen (Lets name our macro as GoGreen; Remember not to use any special characters or space.)
Shortcut key : For now lets leave it as blank.
Store Macro in : This gives you three options to save the macro in; current work book, Personal
Macro Workbook or in New Workbook. Let’s select the current workbook ie.‘This Workbook’
Description : My first macro to fill Green color in cells. (A small description about the
macro you are creating.)
After filling the details click OK.
As soon as you click OK, the Record Macro’s icon turns to a blue button and the same is visible at the bottom of the screen and that indicates macro has started recording; means from now what ever you do in excel will get recorded. This blue button is our Start and Stop button.(Even we can directly start recording macro by clicking this button rather than going to Developer tab and then Record Macro.)
Step3: Go to Home tab and click on Fill Color and from the list of colors displayed click on Green.
Step4: Click on Stop button (The Blue button mentioned above) to stop recording macro.
Now that you have recorded your first macro and you can run it by clicking Developer tab – Macros- Run OR Alt + F8 – Run. But wait a minute lets make it little more beautiful and convenient to use.
Go to Insert – Shapes and click on any shape which you like (I have selected Rectangle). Now your courser turns to a ‘ + ‘ shape that means you can draw a Rectangle in any part of your Excel.
After you draw a Rectangle, right click on it and click on Edit Text and name your shape as GoGreen. And once again right click on the shape and then click on Assign Macro..from the drop-down list.
After you click on Assign Macro, a pop-up window appears then select GoGreen from the Macro name filed and click OK.
You have successfully created your first macro and assigned a button to run that macro, start filling green color by clicking the GoGreen button.
Now that we have to learn how does this macro works. We will learn it from the next chapters. Before that two quick home works:
1. Open VBA editor and try to explore/understand the GoGreen Macro codings by yourself.(Developer tab – Macros – GoGreen – Edit)
2. Record another macro to NoFill the entire sheet and assign that macro to a different shape and name it as Clear all. So thatyou can keep playing with your macro; One to fill the color and another to clear the color.
You can download my free GoGreen Macro Workbook from the below link.
Download Free Macro Workbook
Automate Complex Tasks with Microsoft Excel VBA & Excel Macros (Real-World Projects included). Achieve More. Save time.
t will be a worth investment! And Right Now you can register with upto 80% Off
(Only when you click and join from here ⇊)
Unlock Excel VBA and Excel Macros