Control button / macro

S

Sarah

Hi there,
I have a control button on a spreadsheet. And I have a macro already
written. How do I attach that macro to the button without having to write or
copy the macro code into the control code? I'm really bad at writing that
stuff and I think I am messing up the syntax so wondered if there was an
easier way.
Thanks!
 
T

tylagusim

Le'ts assume your macro is named "myFavoriteMacro" and you want to do
things very, very simply.
On your worksheet, double-click the control button. This will pop-up
the VBE environment with some code pointing to your command button. It
will look something like:
Private Sub CommandButton1_Click()

End Sub
All you need to do is put in the line "Call myFavoriteMacro" before
the "End Sub" and you're there.

HTH
/ Tyla /
 
G

Gord Dibben

You could, as a possible alternative, create your button from the Forms toolbar.

Right-click and "assign macro".

Select your macro by name and OK.


Gord Dibben MS Excel MVP
 
Top