Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Capture button name or row # during click?

I have a worksheet where I have a created a button in column A of
every row.

When the user presses the button for a particular row, I need to know
what row the user pressed the button in so I can take appropriate
action for that row.

Any ideas?!

Thanks.

John

__ WHAT DIDN'T WORK __

I'll include my failed approach but hopefully there's some simple
approach that I'm not thinking of...

When I create the buttons, I change the name to incorporate the row
number, but I can't figure out how to capture the row # based on which
button was pressed. I've tried passing a parameter to the sub with
the ".OnAction" parameter, but that doesn't work.

Example code to create button for 10 rows:

For Loop = 1 To 10
With ActiveSheet.Buttons.Add(Cells(Loop, 1).Left + 3,
Cells(Loop, 1).Top, 30, 10)
.Characters.Text = "Toggle"
.Name = Loop ' Name the button the Loop (i.e. Row #)
.OnAction = "Toggle_Row_Selection " & Loop ' Can't pass
the Row # here
End With
Next AnimalLoop

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Capture button name or row # during click?

On May 9, 5:39 pm, robotman wrote:
I have a worksheet where I have a created a button in column A of
every row.

When the user presses the button for a particular row, I need to know
what row the user pressed the button in so I can take appropriate
action for that row.

Any ideas?!

Thanks.

John

__ WHAT DIDN'T WORK __

I'll include my failed approach but hopefully there's some simple
approach that I'm not thinking of...

When I create the buttons, I change the name to incorporate the row
number, but I can't figure out how to capture the row # based on which
button was pressed. I've tried passing a parameter to the sub with
the ".OnAction" parameter, but that doesn't work.

Example code to create button for 10 rows:

For Loop = 1 To 10
With ActiveSheet.Buttons.Add(Cells(Loop, 1).Left + 3,
Cells(Loop, 1).Top, 30, 10)
.Characters.Text = "Toggle"
.Name = Loop ' Name the button the Loop (i.e. Row #)
.OnAction = "Toggle_Row_Selection " & Loop ' Can't pass
the Row # here
End With
Next AnimalLoop


Never name a variable as one of VBAs reserved words, such as Loop. In
the example below, I renamed Loop to L. Also, in the OnAction
property, you need to assign that to a separate sub routine. You can
capture which button was clicked by using Application.Caller.

Sub foo()
For L = 1 To 10
With ActiveSheet.Buttons.Add(Cells(L, 1).Left + 3, Cells(L,
1).Top, 30, 10)
.Characters.Text = "Toggle"
.Name = L ' Name the button the Loop (i.e. Row #)
.OnAction = "toggler"
End With
Next
End Sub

Sub toggler()
MsgBox Application.Caller
End Sub

HTH
-Jeff-

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default Capture button name or row # during click?

Application.Caller works. I was stumped on this one.

Thank you!

John

P.S. I was just using "Loop" as an example variable, but thanks for
the reminder when posting sample code.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
capture listbox click Joanne New Users to Excel 13 July 7th 07 01:00 PM
Can you capture worksheet double click event from an Add-In???? JGeniti Excel Programming 4 January 23rd 06 07:37 PM
capture right mouse button click event on cell Reinhard Thomann Excel Programming 0 January 20th 05 11:41 AM
Mouse Over Graph, Capture Information on Click(Double Click) Dean Hinson[_3_] Excel Programming 1 December 6th 04 04:49 AM
capture shift-double-click Rob Bovey Excel Programming 0 July 13th 03 09:56 AM


All times are GMT +1. The time now is 09:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"