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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.