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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
@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,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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