• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • SALE 20% Off All Courses
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Logout
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Assign a Macro to a Shape or Use a Shortcut Sequence

You are here: Home / Excel VBA / Assign a Macro to a Shape or Use a Shortcut Sequence
https://www.myonlinetraininghub.com/assign-a-macro-to-a-shape-or-use-a-shortcut-sequence
December 11, 2013 by Philip Treacy

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.

Insert Shape

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.

the fix everything button

Assigning a Macro to the Shape

Right click on the shape and then click on Assign Macro

Assigning the 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.

Pick macro to assign to shape

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.

macro list

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

ctrl+shift+x shortcut

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.

https://www.myonlinetraininghub.com/assign-a-macro-to-a-shape-or-use-a-shortcut-sequence

More Excel VBA Posts

automating and emailing pivot table reports

Automating and Emailing Pivot Table Reports

Automate the creation and distribution of pivot table reports with some VBA. Send reports to multiple email recipients using Outlook.
Checking values in range objects with vba

Checking Values in Range Objects With VBA

Use built in tools or your own code to examine the values contained within Range objects in VBA. Sample code to download.
Static variables in VBA

Static Variables in VBA

Variables normally cease to exist once your Sub or Function has ended. But Static Variables allow you to preserve values after your code has finished.
save chart as image

Save Chart as Image

List all the charts in your workbook then select the ones you want to save as either PNG or JPG. Sample workbook and code to download
Clearing Downstream Dependent Data Validation Lists

Clear Downstream Dependent Data Validation Lists

Change one of your data validation lists and clear the values in the other data validation lists dependent on your first choice.
Excel Status Bar

Excel Status Bar

Use the Excel Status Bar to send messages to your users and to show a progress bar for your VBA code
Progress Bar for Excel VBA

Excel Progress Bar for VBA

Create your own progress bar for VBA in Excel. Use it to show that your code is still running, and how long before it finishes.
error handling in vba

Error Handling in VBA

Understand how Excel VBA generates errors, how to control what Excel does when an error occurs, and how to write your own error handling routines.
Finding File Metadata Using FileSystemObject

Finding File Meta Data Using FileSystemObject

Find file meta data like the creation date, last modified date and file size using Windows FileSystemObject in Excel VBA
Automatically Add Items to Data Validation List

Automatically Add Items to Data Validation List

Automatically Add Items to Data Validation List by typing in the new data. Then sort the source list for bonus points

More Excel VBA Posts

Display All Matches from Search in Userform ListBox

Display All Matches from Search in Userform ListBox

Search a range for all partial and full matches of a string, and display matching records (entire rows) in a userform listbox. Sample code and userform.
animating excel charts

Animating Excel Charts

Use animation correctly to enhance the story your data is telling. Don't animate your chart just for some eye candy. Sample code and workbook to download.
dynamic data validation lists in userforms

Dynamic Data Validation Lists in Userforms

Data validation lists using the same source that are dynamically modified to prevent the same choice being made in each list.
show report filter pages for power pivot pivottables

Show Report Filter Pages for Power Pivot PivotTables

PivotTables created from Power Pivot can't use the 'Show Report Filter Pages' option. But this piece of VBA allows you to do just that.
charting real time data in excel

Charting Real Time Data in Excel

Receive data in real time and chart the data as it arrives. Can be used to chart things like stock prices or sensor readings. Sample code and workbook
select multiple items from drop down data validation list

Select Multiple Items from Drop Down (Data Validation) List

Choose multiple items from a data validation (drop down) list and store them all in the same cell. Sample workbook with working VBA.
Excel Calendar (Date Picker) to Use in Worksheets and Userforms

Multi-Language Excel Calendar (Date Picker) for Worksheets and Userforms

Easy to use, highly customizable and multi-language. This date picker is implemented as a userform that is simple to integrate into your workbook.
automating and emailing pivot table reports

Automating and Emailing Pivot Table Reports

Automate the creation and distribution of pivot table reports with some VBA. Send reports to multiple email recipients using Outlook.
search for data with userform

Searching for Data With a User Form

Search a list of records (like a table) using a user form, and then populate the fields of the search form when the record is found.
Checking values in range objects with vba

Checking Values in Range Objects With VBA

Use built in tools or your own code to examine the values contained within Range objects in VBA. Sample code to download.




Category: Excel VBATag: Excel VBA
Previous Post:Excel Search a Cell for a List of WordsExcel Search a Cell for a List of Words
Next Post:Excel TEXT Function – handy but limited…or is it?Excel TEXT Function – handy but limited…or is it?

Reader Interactions

Comments

  1. Brendon Marks

    June 15, 2019 at 3:11 am

    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.

    Reply
    • Philip Treacy

      June 18, 2019 at 8:49 pm

      Hi Brendon,

      Just hold SHIFT and press another key and the key sequence will show as CTRL + SHIFT +

      Regards

      Phil

      Reply
  2. Carter H.

    October 2, 2016 at 10:33 am

    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!

    Reply
    • Catalin Bombea

      October 4, 2016 at 12:10 am

      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.

      Reply
  3. AggieDave

    July 13, 2016 at 3:31 am

    If the macro is in your personal workbook, does the mapped keyboard shortcut work for any workbook you’re working on?

    Reply
    • Philip Treacy

      July 13, 2016 at 8:54 am

      Yes Dave that is correct.

      Reply
  4. Bryan

    December 12, 2013 at 3:28 am

    > “Fix Everything”. It‘s a little macro I wrote one day.

    Hilarious! I wish I had a macro like that…

    Reply
    • Philip Treacy

      December 13, 2013 at 3:30 pm

      🙂 amazing what you can do with VBA.

      Phil

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Course Sale

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

Guides and Resources

  • Excel Keyboard Shortcuts
  • Excel Functions
  • Excel Formulas
  • Excel Custom Number Formatting
  • ALT Codes
  • Pivot Tables
  • VLOOKUP
  • VBA
  • Excel Userforms
  • Free Downloads

239 Excel Keyboard Shortcuts

Download Free PDF

Free Webinars

Excel Dashboards Webinar

Watch our free webinars and learn to create Interactive Dashboard Reports in Excel or Power BI

Click Here to Watch Now

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
trustpilot excellent rating
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.