So you’ve got some code and you want to be able to run it, but opening up the list of macros (ALT+F8) and choosing the one you want just isn’t quick enough. Or if you have a lot of macros it can get tiresome looking through your list to find the right macro before running it.
So what do you do? You assign the macro to a shape, or you can use a shortcut sequence of keys.
Note : You can also assign macros to form controls like a button, spin button, combo box etc, and to icons you create in your Quick Access Toolbar (QAT) and your Ribbon
Inserting a Shape
Excel has lots of shapes you can use with a multitude of configuration options to play with. You can read our post on Excel Shapes to learn how to insert and configure them. But it's as simple as going to the Ribbon : Insert -> Shapes and choosing the shape. Then use your mouse to position the shape and drag it to the size you want.
You can then play around with the look of it but don’t go nuts. K.I.S.S. I’m just going to use a rectangle, change the colour to green and add some text. Use the text on your shape to convey something meaningful like what the macro will do – which in my case is “Fix Everything”. It‘s a little macro I wrote one day.
Assigning a Macro to the Shape
Right click on the shape and then click on Assign Macro
The list of macros pops up, click on the macro you want, then click OK. You’ll still be editing the shape at this point and you must click off it before you can run the macro, so just click in any cell.
Now just click on your button and run your macro. I just did and I Fixed Everything, so I can go home early 🙂
Using a Shortcut Key Sequence
If you have fingers that are extremely dextrous from maybe playing too much Tetris (yes I have been playing games for a long time) or FPS games (Half-Life/Battlefield/COD anyone?) then maybe a keyboard is your weapon of choice.
In this case you can use a sequence of keys to run your macro. In Excel press ALT+F8 to bring up your list of macros.
Click on the macro you want to use – only click once! Then click on Options and you’ll see the box below.
By default Ctrl is included in the shortcut sequence. You don’t want to hijack a pre-configured shortcut like Ctrl+S, Ctrl+X etc, so I try to use Shift as well to make my sequence unique. In this case I’m going to use CTRL+SHIFT+X
Click OK and you are back to the list of macros. Here’s where the interface isn’t very good. There’s only a Cancel button, but you have to press it, or click the red X button to close the window. Either way I don’t like this as there should be an affirmative option to make me feel like I’m actually saving the changes I just made.
But, click Cancel anyway and your shortcut key sequence is saved.
Shape vs Shortcut
The shape obviously only appears on the sheet you’ve created it on. The shortcut is available from any sheet in your workbook. You can decide which is best for you.
Brendon Marks
When adding a shortcut key sequence I only have the option of Ctrl+ a single key I can’t get the shift key in the sequence.
Philip Treacy
Hi Brendon,
Just hold SHIFT and press another key and the key sequence will show as CTRL + SHIFT +
Regards
Phil
Carter H.
Your posts are very easy to follow. Often times, novice users can get stuck on the simplest of steps, but you walk us through, explaining every bit. One question: I see my code in a module, but when I try to run a macro, the sub doesn’t show up in the list of macros. Any idea as to why this is happening and how to fix it? The whole purpose of having a macro is to simplify. I don’t want to have to open the module and run from vba editor. Thanks!
Catalin Bombea
Hi Carter,
Make sure it’s a Sub, or a Public Sub, a Private Sub will not show up in Alt+F8 list of macros.
AggieDave
If the macro is in your personal workbook, does the mapped keyboard shortcut work for any workbook you’re working on?
Philip Treacy
Yes Dave that is correct.
Bryan
> “Fix Everything”. It‘s a little macro I wrote one day.
Hilarious! I wish I had a macro like that…
Philip Treacy
🙂 amazing what you can do with VBA.
Phil