Create a Macro Button in Excel
The most common tasks in Excel can be automated to avoid unnecessary time consumption. Having talked about automation VBA macros is the way to go forward in excel; once the macro coding is done, we need to execute that program to get the assigned job done. You must have already seen a button that can do the job in many of the worksheets, so once the programming is done, we can assign that work to one of the buttons, so by just click of the button, the assigned job will be executed. So in this article, we will take you through the process of creating an excel button to execute the task.
3 Methods to Create Button in Macro Excel?
As we know, macro coding is the perfect way to automate tasks; there is a small other thing we can do to execute that code. Macro & Buttons are the perfect combinations; it is like a “typical Indian marriage of boy likes a girl and girl likes a boy.” By just as the click of the button, we can execute hundreds of lines, so some of the complicated reports can be automated and hand over to your team members and say all they have to do is to click the button to get the job done.
So, in excel, we can create an excel button using three ways, and those are below.
- Shapes
- Active X Control
- Form Control in Excel
We will see each one of them in detail now.
#1 – Using Shapes
The best and easy way to create a button to assign macro is using “Shapes” of Excel. We can insert a wide variety of shapes in excel, and also we can format these shapes as we would like to make them look.
Before inserting shapes, below is the macro we had written to filter values in the below data.
We have data in columns from A to E, and in G2 cell, we have created a drop-down list of all the card types, the card type that we choose in the G2 cell should be filtered out in the data and for this, below is the excel macro code we have written.
Code:
Sub Filter_Values() Dim LR As Long Dim LC As Long Dim Rng As Range LR = Cells(Rows.Count, 1).End(xlUp).Row LC = Cells(5, Columns.Count).End(xlToLeft).Column Set Rng = Cells(5, 1).Resize(LR, LC) Rng.AutoFilter Field:=4, Criteria1:=Range("G2").Value End Sub
Upon running the above code, it will filter the values which are selected in the cell G2 cell. Every time we need to open the Visual Basic Editor, and we need to run the code.
4.9 (1,353 ratings) 35+ Courses | 120+ Hours | Full Lifetime Access | Certificate of Completion
So, now we will insert shapes to assign the macro.
Step 1: Go to the INSERT tab in excel and find the “Shapes” option.
Step 2: Once you click on the drop-down list of “Shapes,” we will see many shapes options.
Select any of the shapes and draw on the worksheet (above the data table).
Step 3: After adding the shapes, we need to enter some text value to it, so right-click on the shape and choose “Edit Text.”
Step 4: Enter text as you would like to convey the message to the user.
Step 5: This is the default view of the shape, so we can format it under the “Format” tab.
Step 6: Once the proper formatting is given to the shape right click and choose “Assign Macro.”
Step 7: Now, this will open up all the macro names in the visual basic editor.
Choose the macro that you would like to assign to the shape.
Step 8: Now click on “Ok,” and macro has been assigned to the shape.
Now when you hover on the shape, you can see the hand pointer indicating the click option.
Now, if you click, the assigned macro will be executed, and the value which is there in cell G2 will be filtered.
#2 – Using Form Control Shapes & Active X
Under the developer tab, we have an option called “Insert”; under this; we have “Form Control” and “Active X Control.”
From “Form Controls,” select the “Button” option.
Draw this on your worksheet, and immediately you will get a list of macros.
Choose the macro that you would like to assign and click on “Ok” to close the above window.
Now Button is created to run the macro.
Like this, we can create a button in excel to execute the macro.
Things to Remember
- The Active X Control button requires further coding knowledge, so not covered in this article.
- The basic difference between Shape & Form control is the formatting and style they look.
Recommended Articles
This has been a Guide to Create Button Macro in Excel. Here we discuss the Top 3 Methods using shapes, active X control, and form control along with examples and downloadable excel templates. You may learn more about excel from the following articles –
- 35+ Courses
- 120+ Hours
- Full Lifetime Access
- Certificate of Completion