BLOGS BY TOPIC
BLOGS BY AUTHOR
BLOGS BY YEAR
If you're not sure what the Excel Visual Basic for Applications language is (or how it can help you) this blog attempts to explain! Learn what VBA is, and how you can record macros and then replay them again and again to automate work in Excel.
- How to Record Macros in Excel Visual Basic
- What is Excel VBA, and how can you use it?
- Starting to Record Macros in Excel VBA
- Recording your Macro and Finishing
- Tidying up your macro that has been recorded
- Playing back your macro recorded in Excel VBA (this blog)
Posted by Andy Brown on 30 June 2011
You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Playing back your macro
You can play a macro that you've recorded (and possibly edited) in several ways:
- by pressing the relevant short-cut key
- by creating a button on your worksheet
- by assigning it to a picture or drawing
- by adding a button to the Quick Access toolbar (or creating a new toolbar in Excel 2003)
The rest of this blog shows how to do each of these things.
Running a Macro Using a Short-Cut Key
If you've assigned a short-cut key to your macro, you can press it now. In our case, it was SHIFT + CTRL + R.
Running a Macro Using a Button
The steps to assign a macro to a button are shown below:
To insert a button:
You can now click and drag to form the outline of your button:
Click and drag with the plus symbol to draw your button.
When you release the mouse button, you can choose which macro to assign to your button:
Choose from the list of macros that you've written - this appears automatically.
Finally, you can change the text displayed on your button:
Click and drag across the text of the button, and type something else in.
You've now got a clickable button! Note that in Excel 2003 you can achieve the same thing from the Forms toolbar:
Right-click on any Excel 2003 toolbar and choose to display the Forms toolbar (from this you can insert a command button).
Running a Macro Using a Picture
The only hard thing about assigning a macro to a picture is choosing the right picture!
Paste any picture onto your worksheet, then right-click on it to assign a macro to it as shown here.
Running a Macro from the Quick Access Toolbar
This option is different - and more complicated - in Excel 2003, so only the 2007/2010 method is shown here.
Our aim is to get an icon to appear on the Quick Access toolbar, so start by right-clicking on it:
Right-click anywhere on the toolbar at the top left of Excel to customise it
You can now choose a macro to assign to it:
Follow the numbered steps below!
The numbered steps shown above are:
- Choose to display a list of macros.
- Double-click on the macro you want to assign an icon to.
- Click on the macro where it appears in the right-hand list to select it.
- Click on the button to modify the icon, and choose a different picture.
If you follow these steps carefully, you'll end up with a custom icon:
Here I've gone for a pi symbol (or should that be tau?), for no particular reason. Clicking on this tool will run the macro.
Your customised quick access toolbar will remain visible even when the workbook containing your macro is closed down. If you click on the icon in this case, Excel will automatically open the workbook and then run the macro, which is pretty much what you'd want and expect.
So that's how to record macros! The next step, perhaps, is to learn how to write macros ...