If you have a repetitive task that is a good candidate for a macro, you can use the macro recording capabilities of Excel to turn your actions into a macro. To record a macro, follow these steps:
Figure 1. The Record Macro dialog box.
Excel starts recording everything you do. The actions you take become steps in the macro and will be repeated when you later execute the macro. When you have finished the steps you want recorded in your macro, again display the Developer tab of the ribbon and click the Stop Recording tool. (This tool is only available when you are actually recording your macro.) The macro is then saved and available for use at any time.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (5683) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Recording a Macro.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Excel allows you to format numeric values in many different ways, including as currency. If you want to determine, in a ...
Discover MoreMacros can allow you to do some fancy data validation in your workbooks, such as checking to see if the user entered ...
Discover MoreMany times you need to select just the visible cells before taking some action. It is helpful to know how to make this ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-03-29 17:23:53
Dennis Costello
I haven't used the Record a Macro feature recently, but found it was a great way to begin to learn the basics of VBA (pun intended). One thing that annoyed me is that it always seemed to generate VBA code that looked more or less like this:
<range>.SELECT
SELECTION.<action>
I would almost always shorten these sequences to <range>.<action>
For instance, instead of
Range("F54").Select
Selection.Font.Bold = True
generated by the Macro Recorder, I would use
Range("F54").Font.Bold = True
This is, in my opinion, not only easier to read and understand, but possibly also executes faster - because Selection could be a simple range of a single cell, or a "3-dimensional" selection across multiple tabs and including multiple areas on each, and so VBA interpreter has to wade through code that can handle all the possible cases. Writing it my way, the interpreter can see right away that the action is being taken on a simple range.
I don't know if this is significant for VBA, but in other interpreted languages I've worked with in the past that include a similar Select concept, it did matter.
Having said that, the way the Recorder shows it might be the more "honest" approach - recording clicking on a cell as a Select, separate from the action taken on the cell(s) so selected.
2018-11-23 05:47:27
Peter Atherton
Raymond
Seems like you use a Mac. On windows there is a short-cut to save the document Ctrl + S, Ctrl + P to print and so on. If you use these shortcuts in your workbook then you will not be able to use them to save or print a file. The usual worokaround is to add the Shift to yhe short cut. e.g Ctrl + shift + S. Try these short cuts to make sure that Excel is nt usng them before they are apied to your workbook.
HTH
2018-11-22 13:02:26
Raymond A Batman
When I use the ctrl+ command I get an insert box that provides ways to shift cells. So that does not allow me to use a shortcut key to record a macro?
2018-11-19 05:50:16
Barry
@JeanE
The macro recorder default to using absolute addresses, which is a nuisance as the majority of times, that I've used the recorder, I want relative addresses. Fortunately, this is easily enabled by slicking the "Use Relative References" in the ribbon on the 'Developer' tab or on older versions of Excel the Use RElative Reference button on the floating "Macro" recorder toolbar.
You can switch between absolute and relative as frequently as you like during the recording of the macro. E.g. I had a macro to go to the last entry in column A - in absolute mode go to the last cell in column A then switch relative to then use the [End} [UpArrow] to go to the last cell.
2018-11-18 11:40:31
JeanE
The steps mentioned to create a macro work great, but only on the cell the macro was recorded in. How do I make the macro run in any other cell in the workbook -- in other words, address free?
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2022 Sharon Parq Associates, Inc.
Comments