Worksheet Button Callbacks

M

Mike Lynch

I have embedded several buttons within different cells of
an Excel worksheet, all of which reference the same
procedure upon clicking. Within the procedure I need to
determine the cell location (BottomRightCell or
TopLeftCell.. I think) of that button. Have searched
knowledge base, Micorsoft help and text books to no avail.

Any thoughts?
 
T

Tom Ogilvy

If you mean buttons from the forms toolbar, and if you don't it is far
easier to do this with those buttons, you would use Application.Caller

Sub Button_Click()
sName = Application.Caller
set btn = Activesheet.Buttons(sName)
set rng = btn.TopLeftCell
msgbox "you pressed " & sname & vbnewline & _
"located above cell: " & rng.address
End Sub

Then assign this macro to each of your buttons from the forms toolbar.

Regards,
Tom Ogilvy
 

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