Command Button Position

foxtrot23

New Member
Joined
Aug 19, 2011
Messages
2
I'm trying to create a command button that when clicked, passes it's location through to the on click procedure (I eventually want to use it to delete the row that it is in). I supposedly can make use of ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row to do this but I am getting an error. My procedure at the moment is as follows:

Code:
Private Sub CommandButton1_Click()

    MsgBox ("Row of pressed button: " & ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row)

End Sub

When I hit the button and the procedure is run, I get the error Run-time error '13' Type Mismatch.

I'm obviously doing something wrong here. Any assistance would be greatly appreciated.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I suspect you are using an "ActiveX" button instead of a "Forms" button. The code you have shown is for a "forms" button.

Gary
 
Upvote 0
Welcome to MrExcel.

You can't use Application.Caller with a CommandButton from the Control Toolbox. Try instead:

Code:
Private Sub CommandButton1_Click()
    MsgBox "Row of pressed button: " & CommandButton1.TopLeftCell.Row
End Sub
 
Upvote 0
Thanks so much for your responses - they're much appreciated. After reading them I figured that an ActiveX button probably suits my purposes better anyway. Being a newbie to Excel I'm still feeling my way around!
 
Upvote 0
foxtrot23:

You say "Being a newbie to Excel I'm still feeling my way around!"

Well..

Me being an oldie to Excel I'm still feeling my way around!

Jim
 
Upvote 0
The type mismatch is that you are trying to cocatenate a string and a range object. Try adding .Address

Code:
MsgBox "Row of pressed button: " & ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row[COLOR="Red"].Address[/COLOR]
 
Upvote 0
The type mismatch is that you are trying to cocatenate a string and a range object. Try adding .Address

Code:
MsgBox "Row of pressed button: " & ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row[COLOR=red].Address[/COLOR]

Did you try that Mike? Application.Caller won't work with ActiveX controls.
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top