ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   determine row reference from button (https://www.excelbanter.com/excel-programming/310995-determine-row-reference-button.html)

mark

determine row reference from button
 
I'm creating a timesheet and need a button to copy data
from one column to others for the specific row the button
is on.

I've created a button click which passes the row reference
(value is assigned to click event) across to the function
which does the copying.

Problem is, I can't seem to get the row reference value
(to pass to function) based on the location of the button.

Is there a way to get this row reference from the button
location or another way?

I really don't want to have to create a click event for
each and every button and lock in the row reference ,
cause there is loads of them.

Many thanks in advance

mark

Dave Peterson[_3_]

determine row reference from button
 
Where did you get the button?

if from the Forms toolbar:

sub mybuttonclick()
dim myBTN as button
set mybtn = activesheet.buttons(application.caller)
msgbox mybtn.address & vblf & mybtn.row & vblf & mybtn.column
end sub

if from the Control toolbox:
Private Sub CommandButton1_Click()
msgbox me.commandbutton1.row
end sub

mark wrote:

I'm creating a timesheet and need a button to copy data
from one column to others for the specific row the button
is on.

I've created a button click which passes the row reference
(value is assigned to click event) across to the function
which does the copying.

Problem is, I can't seem to get the row reference value
(to pass to function) based on the location of the button.

Is there a way to get this row reference from the button
location or another way?

I really don't want to have to create a click event for
each and every button and lock in the row reference ,
cause there is loads of them.

Many thanks in advance

mark


--

Dave Peterson


Dave Peterson[_3_]

determine row reference from button
 
I got a private response pointing out my typo:

For the Forms version:

Option Explicit

Sub mybuttonclick()
Dim myBTN As Button
Set myBTN = ActiveSheet.Buttons(Application.Caller)
MsgBox myBTN.TopLeftCell.Address & _
vbLf & myBTN.TopLeftCell.Row & _
vbLf & myBTN.TopLeftCell.Column
End Sub

(sorry)


Dave Peterson wrote in message ...
Where did you get the button?

if from the Forms toolbar:

sub mybuttonclick()
dim myBTN as button
set mybtn = activesheet.buttons(application.caller)
msgbox mybtn.address & vblf & mybtn.row & vblf & mybtn.column
end sub

if from the Control toolbox:
Private Sub CommandButton1_Click()
msgbox me.commandbutton1.row
end sub

mark wrote:

I'm creating a timesheet and need a button to copy data
from one column to others for the specific row the button
is on.

I've created a button click which passes the row reference
(value is assigned to click event) across to the function
which does the copying.

Problem is, I can't seem to get the row reference value
(to pass to function) based on the location of the button.

Is there a way to get this row reference from the button
location or another way?

I really don't want to have to create a click event for
each and every button and lock in the row reference ,
cause there is loads of them.

Many thanks in advance

mark



All times are GMT +1. The time now is 07:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com