VBA Code to get row number of a clicked button

amirkharkongor

New Member
Joined
Nov 8, 2021
Messages
11
Office Version
  1. 2019
  2. 2016
  3. 2010
Platform
  1. Windows
  2. Web
Hi,

I created multiple buttons through the following code :

Set Btn = ActiveSheet.Buttons.Add(bRowRng.Left, bRowRng.Top, bRowRng.Width, bRowRng.Height)
Btn.Caption = "Update"
Btn.OnAction = "Update"
Btn.Name = "BtnName" & BtnCnt


Now I want to write another code to get the row Number of the above buttons.

I tried the following solution available in this forum but i got an error "Unable to get the Buttons property of the Worksheet class"

Sub Mainscoresheet()
' Mainlineup Macro
Dim b As Object, RowNumber As Integer
Set b = ActiveSheet.Buttons(Application.Caller) ["Unable to get the Buttons property of the Worksheet class"]
With b.TopLeftCell
RowNumber = .Row
End With
MsgBox "Row Number " & RowNumber
End Sub

Kindly help me.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
How are you running the Mainscoresheet macro?
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
But now I am having another problem.

While using the following code I am getting a compile error expected function or variable.

Set Btn = ActiveSheet.Buttons.Add(bRowRng.Left, bRowRng.Top, bRowRng.Width, bRowRng.Height)
Btn.Caption = "Update"
Btn.OnAction = BtnUpdate [expected function or variable]
Btn.Name = "BtnName" & BtnCnt

calling the following function

Sub BtnUpdate()
rowNo = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
MsgBox "Test Row No. : " & rowNo
End Sub
 
Upvote 0
That needs to be in quotes.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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