Retrieving name from command button on Worksheet

G

Google

I'm using Excel 2000 under win2K and have several command buttons on a
worksheet and assigned the same macro to them.
In the macro I want to find out WHAT button has been clicked
(extracting a number I attached to a name to privide as parameter in a
function). I don't want to create a bunch of macro's just to identify
each command button separately.
How do I do that?
 
J

Jim Cone

If you are using buttons from the Forms toolbar then
"Application.Caller" returns a string with the button name.
Extracting a single digit suffix from the button name
could work like this...

Sub CommonSubCalledByAllButtons()
Select Case Right$(Application.Caller, 1)
Case "1"
'do something
Case "2"
'don't do something
Case "3"
'do something else
Case "4"
'have lunch
End Select
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


I'm using Excel 2000 under win2K and have several command buttons on a
worksheet and assigned the same macro to them.
In the macro I want to find out WHAT button has been clicked
(extracting a number I attached to a name to privide as parameter in a
function). I don't want to create a bunch of macro's just to identify
each command button separately.
How do I do that?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top