While working in Microsoft Excel sometimes we need to do a task again and again inside a workbook. For that, you can simply assign a macro to a button so that you don’t have to repeat the same procedure for every sheet. Just click the button and your work will be done as assigned. In this article, we shall learn how to assign a Macro to a button in Excel. Let’s start.
Download Practice Workbook
Download this practice workbook to exercise while you are reading this article.
2 Simple Methods to Assign Macro to Button in Excel
In the following, I have shared 2 simple and easy methods to assign a macro to a button in excel.
Suppose we have a dataset of some Student Names and their Exam Results in a worksheet. Now we will assign a macro to a button in excel.
1. Use Form Control Feature to Assign Macro to Button in Excel
After you have recorded and tested a macro, you may want to assign your macro to a button placed on a worksheet. Simply use the developer feature to do so-
- First, press the “Button” icon from the “Insert” option to create a button inside your worksheet.
- Secondly, draw a button anywhere on your worksheet.
- After drawing the button a new window will appear asking to assign a macro for the created button.
- Gently, choose your macro and select “This workbook” from the drop-down list below.
- Press OK.
- Therefore, selecting cells click the button icon to get the output.
- Finally, you will see the selected cells are colored according to the macro. This way you can create and assign a macro to a button in excel.
Read More: 22 Macro Examples in Excel VBA
- VBA Macro to Delete Row if Cell Contains Value in Excel (2 Methods)
- A Macro example created using VBA
- Necessary Aspects About Macro Security in Excel
2. Insert Shape to Assign a Macro in Excel
If you want you can also insert your desired shape and then assign a macro of your choice. To do so-
- Starting with, let’s create a shape from the “Insert” option. Here I have selected the “Oval” shape to draw inside the spreadsheet.
- Hence, selecting draw the shape at any position on your worksheet.
- In the same fashion, let’s assign a macro for the drawn shape by right-clicking the mouse button and choosing “Assign Macro“.
- Now, choose your macro, and then from the drop-down list select “This Workbook“.
- Hit the OK button to continue.
- In addition, you can change the texts inside the shape from the “Edit Text” option.
- Then, select any cell from the worksheet and press the “Shape” which is assigned with the macro.
- In conclusion, we will get the output as assigned in the macro code. This is the simplest way to assign a macro in excel.
Read More: How to Edit Macros in Excel (2 Methods)
Things to Remember
- While working in Microsoft Excel, you might not find the “Developer” option in the top ribbon of the workbook. In that situation just got to File > Options > Customize Ribbon. From the dialog box checkmark the “Developer” feature and press OK to get it.
In this article, I have tried to cover all the methods to clean data in excel. Take a tour of the practice workbook and download the file to practice by yourself. I hope you find it helpful. Please inform us in the comment section about your experience. We, the Exceldemy team, are always responsive to your queries. Stay tuned and keep learning.
- How to Create Button Without Macro in Excel (3 Easy Ways)
- Remove a Form Control in Excel (3 Quick Ways)
- How to Insert Excel VBA Radio Button Input Box (3 Easy Methods)
- Group Radio Buttons in Excel (2 Simple Methods)
- How to Add Option Button in Excel (With Easy Steps)
- Change Color of Toggle Button When Pressed in Excel
- How to Create & Apply Option Button Click Event in Excel VBA