determine row reference from button

  • Thread starter Thread starter mark
  • Start date Start date
M

mark

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
 
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
 
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)
 
Yeah, and this one was wrong, too:

msgbox me.commandbutton1.row
maybe this would work:
msgbox me.commandbutton1.topleftcell.row
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top