Get button position

tyhonex

New Member
Joined
Jun 22, 2023
Messages
2
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
  2. MacOS
Hello I just need to do a basic thing. When I press button I want to get the location of button for example to mgsbox.
My code is here:

Sub GetLocation()
Dim Row As Long
Dim Column As Long


Row = Application.Caller.Row
Column = Application.Caller.Column

MsgBox "Row:" & Row&

End Sub

Error: Object requied


Thank you for you help
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
@tyhonex Welcome.
Does the below help?

VBA Code:
Sub GetLocation()
Dim Shp As Shape
Dim Row As Long
Dim Column As Long
Set Shp = ActiveSheet.Shapes(Application.Caller)

MsgBox "Address " & Shp.TopLeftCell.Address

MsgBox "Row " & Shp.TopLeftCell.Row

MsgBox "Column " & Shp.TopLeftCell.Column

End Sub
 
Upvote 0
Yea, its working. Thank you. Just one more question how to save number of row to Row and number of column to Column, because
Row = Shp.TopLeftCell.Row is now working

Thank you Sir
 
Upvote 0
Avoid using VBA code keywords like: Row,Column
With R is row and C is column, try:
VBA Code:
Sub GetLocation()
Dim R As Long
Dim C As Long
With ActiveSheet.Shapes(Application.Caller).TopLeftCell
    R= .Row
    C= .Column
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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