You are on page 1of 3

13/09/2016 How 

to Write a Simple Macro in Microsoft Excel

How to Write a Simple Macro in Microsoft Excel
Two Methods: Excel 2007 and 2010 Excel 2003

Increase the usability of your Excel spreadsheets by adding a little programming to them. While Excel's formulas and
spreadsheet features make it a great tool, mastering the ability to create macros will make it even greater and faster to work
with. Learn how with these steps.

Method
Excel 2007 and 2010
1

1 Click the Developer tab on the Ribbon at the top of the screen. If the tab is not showing up on your screen,
you can add it as follows:
For Excel 2010: click the File Tab then select options. On the left hand side of the Excel options dialog box,
click Customize Ribbon. Then, on the right hand side box select Developer.
For Excel 2007: click the Microsoft Office button, then Excel Options. In the Popular category, under Top
Options for Working with Excel, select Show Developer Tab in Ribbon.

2 Change the security settings. In Trust Centre, Under Macro Settings, click Enable All Macros, then click OK.

Note that this security setting is not ideal for basic use. When you've finished creating your macro, go back and
un­click Enable All Macros.

3 Click Record Macro. You'll find it on the Developer tab under Code.

4 Name your macro. The first character of the name must be a letter; after that, you can use characters, numbers
and underscores. Macro names cannot have spaces.
Don't use the same name for your macro as an existing cell reference.

5 Set a shortcut for your macro (optional). Type a letter in the Shortcut Key box. A lowercase letter will translate
to CTRL + letter; an uppercase letter will be CTRL + SHIFT + letter.

6 Choose where to store your macro. In the Store Macro In list, select the workbook where you want to store the
macro. If you want it to be available whenever you run Excel, select Personal Macro Workbook.

7 Describe your macro. Write this in the Description box.

8 Click OK to start recording your macro.

9 Perform the actions you want the macro to record.

10 Stop recording. Go to the Developer tab, click Code, then click Stop Recording.

Method
Excel 2003
2

1 Change the security level. Switch the security level from Medium to Low.

Click Tools ­> Options ­> Security.
Click Macro Security.
Select Security Level. Select Low.

http://www.wikihow.com/Write­a­Simple­Macro­in­Microsoft­Excel 1/3
13/09/2016 How to Write a Simple Macro in Microsoft Excel

2 Start recording your macro. Navigate to Tools ­> Macro ­> Record New Macro.

3 Name your macro. The character of the name must be a letter; after that, you can use symbols, numbers or
underscores. No spaces are allowed.
Don't use the same name for your macro as an existing cell reference.

4 Code a shortcut for your macro (optional). Enter a letter in the Shortcut Key box. A lowercase letter will make
the shortcut CTRL + letter; uppercase will be CTRL + SHIFT + letter.

5 Choose where to store your macro. In the Store Macro box, select a location for your macro. Click Personal
Macro Workbook if you want it to be available whenever you open Excel.

6 Write a description of your macro.

When you're done, click OK.

7 Record your macro. Remember, Record Macro is still on. Carry out the actions that you want Excel to record as
your macro.

8 Click Stop Recording. You can find this option on the Stop Recording toolbar.

Can you answer these readers' questions? Refresh

On How to Become a Radiologist, a reader asks:
What should a ten­year­old know if he wants to become a radiologist?

Your answer... Reply

On How to Write a Master's Thesis, a reader asks:
How is a research proposal written?

Your answer... Reply

On How to Replace an Ink Cartridge in the HP Officejet Pro 8600, a reader asks:
Printer is telling me the cartridge is older generation; I didn't know that when I bought
it ­ please help me with this problem! What can I do?

Your answer... Reply

Tips

If you already know the code for your macro, you can enter it in the Microsoft Visual Basic Editor. In Excel 2007 and 2010,
it's located under the Developer tab, in Code. In Excel 2003, click Tools ­> Macro ­> Visual Basic Editor.
You can make your macro behave as one of Microsoft Excel's formula functions so you can use it inside the spreadsheets
to calculate things. Basically you have to change your "Sub" to a "Function", add parameters and return a value, but this is
explained in its own how­to, look for it in the related wikiHows section.
Use the Range, Sheet and Workbook objects to interact with the information in your worksheets. The ActiveWorkbook,
ActiveSheet and Selection objects point to the current book, sheet and range of cells in the Application.
The forums at ExcelForum are filled with helpful people who will work hard to answer your politely asked Excel questions.

http://www.wikihow.com/Write­a­Simple­Macro­in­Microsoft­Excel 2/3
13/09/2016 How to Write a Simple Macro in Microsoft Excel

Warnings

Due to security measures, some people may disable macros. Make sure you let your colleagues know the book you're
sending them has macros and that they can trust they're not going to damage their computers.

http://www.wikihow.com/Write­a­Simple­Macro­in­Microsoft­Excel 3/3

You might also like