Adding a macro to a Command Button

Mabocat

Board Regular
Joined
Apr 20, 2011
Messages
74
I created a Command Button on one page of a spreadsheet and managed to give it a Title so how do I link a macro that I have already created to this button ?
I an using Excel 2010

Ron
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you wanted to know the answer to your original question, tell us whether the Command Button was from the Form Controls or the ActiveX Controls section.
 
Upvote 0
.. it was from ActiveX Controls section.
Then the process would be.
- On the Developer ribbon tab enter 'Design Mode' via the button of that name.
- Right click the Command Button and choose "View Code".
- That should take you to the worksheet's module in the vba window & present you with code like
Code:
Private Sub CommandButton1_Click()

End Sub
- Just enter the name of your macro between those lines. So if your macro was called Do_Stuff it would become
Code:
Private Sub CommandButton1_Click()
  Do_Stuff
End Sub
- Back at the worksheet, exit Design Mode by clicking that ribbon button again.
 
Upvote 0

Forum statistics

Threads
1,214,878
Messages
6,122,062
Members
449,064
Latest member
scottdog129

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top