How to run the same macro from two ActiveX CommandButtons

Hello Experts,
I want to run the same macro assigned to CommandButton21 located on Sheet5 from a new, second CommandButton2 on Sheet 5.  Is there a way to "call" the macro without having to repeat (copy) the macro routine for the second CommandButton2?  Because the button toggles colors and changes text each time invoked, I don't want a solution using a shape.
Berry
Berry MetzgerLean process improvement consultantAsked:
Who is Participating?
 
Saurabh Singh TeotiaCommented:
Since you don't want to create another shape..what you can do is... create  a macro for both of them and refer to that macro which will do what you are looking for...

What i mean is this..lets say we call this macro abc...

Private Sub CommandButton21_Click()
abc
End Sub

Private Sub CommandButton2_Click()
abc
End Sub

Sub abc
'Your code here..
end sub

Open in new window

0
 
NorieVBA ExpertCommented:
Will the code for each button be the same?

If it is you could move it to a sub in a standard module and you could call that sub from the buttons' click event.

If it isn't, how does it change for each button?
0
 
Berry MetzgerLean process improvement consultantAuthor Commented:
This example code will work for me. Thanks for the example.  
I think Norie is saying the same thing, so I gave credit for the answer too.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.