Video: Work with macros

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

The best way to automate a repetitive task in Excel so that you can do the task again with a single click? Record a macro.

Want more?

Create or delete a macro

Edit a macro

Assign a macro to a button

Create and save all your macros in a single workbook

You want to automate a repetitive task in Excel, so that you can do the task again with a single click.

The best way to do that? Record a macro.

The macro recorder is the easiest way to create a new macro in Excel.

A quick note: Macros aren't available in Office on a Windows RT PC.

To see what version of Office 2013 you are running, click FILE and then click Account.

If you are on a Windows RT PC, you'll see Microsoft Office 2013 RT here.

Now before we get started, I want to make sure the DEVELOPER tab is available on the ribbon.

That's where all of the macro commands are.

I click the FILE tab > Options > Customize Ribbon, and over here, I select Developer, and then click OK.

Now, I see the DEVELOPER tab and here in the Code group are the Record Macro button and some other buttons I'll go over later.

So, let's get started.

I'll record an auto-fill operation where I build a series of days based on typing Sunday in a cell. After I type Sunday, I right-click the cell and drag it to the right.

As I move over here, the Tool Tips show what will go in each cell, all the way through Saturday.

When I get over here, I release the right mouse button and click Fill Series.

That's what we want to record. So, I'll clear these cells and select A1.

I'll repeat these steps, but this time, I'll turn on the macro recorder. I click the Record Macro button.

Let's name this macro, "FillDays". Macro names can't contain spaces. I click OK to start the recorder.

See how the Record Macro button turned to Stop Recording. When I'm done, I'll click that.

We are done with our auto-fill, and since that's all we wanted to record, I'll click Stop Recording.

Now I'll clear these filled cells to clean up the worksheet, and select A1 again so we can test our macro.

I'll click the Macros button to bring up the Macro dialog box, and click Run.

Perfect, so far.

I'll clear these cells again, and this time I'll select a cell in a different column and row C3, just to test the macro a little more.

Watch what happens.

The macro filled-in A1 through G1. In other words, it failed.

So, why that happened?

It happened because, by default, the macro recorder was using absolute references.

Before I started recording, I should have turned on Use Relative References.

By using relative references, the macro will build a series by selecting the active cell and 6 cells to its right, instead of building a series using A1 through G1.

Well, I know I need to record a new macro.

So, I'll clear these cells, and turn on Use Relative References.

Just to change things up a bit, let's start at cell B5.

So, I click Record Macro, give it a new name, "FillDaysRelative", and click OK to start recording.

I'll type Sunday, do my auto-fill, and Stop Recording.

Now, I'll clear these cells and I'll switch to cell C7 and run my macro from there.

This time, I choose "FillDaysRelative" and Run, and now it works perfectly.

So, you can see that the relative references setting can be very important.

In the next video, we'll rewrite the "FillDaysRelative" macro manually in an Excel tool called the Visual Basic Editor, so that it'll do something a little bit different.

Connect with an expert
Contact us
Expand your skills
Explore training

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.

×