In this video we're going to cover how to record a macro which is a very helpful tool when trying to
quickly automate simple processes or when trying to find the right terminology to accomplish something
in VBA to start we need to be on the developer tab of the ribbon under the code section.
Go ahead and click on record macro.
Now what recording a macro essentially does is record all of your clicks and interactions with Excel.
And it turns them into a macro for you to run again in the future to execute those same actions.
We'll go through an example of that shortly but first let's talk about this window that pops up.
You have the option to enter a name so we'll go ahead and put recorded macro like so and this name will
actually give us an error message but we'll talk about that in a minute.
The shortcut key can be used to tie your macro to a combination of keys on your keyboard to run quickly
and automatically the store macro dropdown is mainly intended for multiple workbooks being open at the
same time so we can ignore that for now.
Lastly you have the option to put a description of your macro in and that's to help other users know
what this macro does without having to look at and understand the code.
So let's go ahead and click ok and we see we get an error message that pops up their message says the
syntax of the name is incorrect.
In our case it's because we put a space in the middle of the name.
Generally speaking it's best practice when coding to avoid unnecessary spaces and instead replace them
with underscores.
And there are several reasons for this which will be made clear in the details of coding and VBA.
For now click OK.
And change the name to recorded underscore macro
and go ahead and click ok.
Now we can see up here the record macros Button has actually turned into a stop recording button and
that's where you'll go to click when you're done doing all of your actions and completing your macro
to just give an example of what this might look like.
Go ahead and click into any cell and type a click out of that so click back into that cell.
Go to home and give it some sort of formatting whatever color whatever sized text whatever background
color you'd like.
Then go back to developer and click stop recording.
Now if we click on our macros button here we can see we have a recorded macro that's showing up go ahead
and close out of that and let's go take a look at what the macro actually looks like in order to do
that on your developer tab click on the Visual Basic button to pull up the Visual Basic window under
the modules folder in your project Explorer window you should see a module one double click on this
to open it and we can see here this is our recorded macro.
Now I'm not going to walk through the details of what each of these lines mean we'll cover the details
of all of VBA and feature videos but to give you a general idea these lines selected the cell and made
its value a these lines changed the background color of that cell to be yellow these lines changed the
font to be red and these lines increased the size of that font and this end sub means that's the end
of this particular macro.
So just to give an example of what running this macro might look like.
Go ahead and exit out of your VBA window Let's insert a new sheet down here under macros select recorded
macro and click Run and we can see the system copied all of the actions that we had done previously
on sheet 1 and did the same thing on this new sheet sheet too.
So this was a very simplified example of when you might be able to use record macro but you should have
a good idea now of how to use this tool to either get the terminology you need to accomplish something
in VBA or to record a series of relatively simple small steps and try to automate your processes.