Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Lots of similar buttons need to call a macro but need to find outwhich button was clicked

Hi

In my spreadsheet I've got about 20 buttons which need to call a
macro, but the macro code needs to be based on the row in which the
button was pressed. Is there a good way of finding out the current
row. Activecell doesn't change when you press the button.

I know I can in each of the click events of the buttons call the macro
and pass in an argument for the row number. Just thought there was a
better way.

I am happy to use labels, autoshapes or buttons if this affects a
suggestion.

Many thanks

Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Lots of similar buttons need to call a macro but need to find out

Buttons are part of controls which are really shapes. Shapes do not have
rows and columns but are positions by the left and top properties which are
in pixels. Cell also have Top and Left properties which can be used to
position shapes.


In this case I recommend hard coding the row number. Each button will have
its own click event and put the row number in the click function. You can
have each of the click events call a common routine like below

Private Sub OptionButton1_Click()
MyRow = 5
call commmonbutton(MyRow)
End Sub
Private Sub OptionButton1_Click()
MyRow = 6
call commmonbutton(MyRow)
End Sub
Private Sub OptionButton1_Click()
MyRow = 7
call commmonbutton(MyRow)
End Sub
sub commmonbutton(MyRow as Integer)
'put common code here
end sub
"Guabble" wrote:

Hi

In my spreadsheet I've got about 20 buttons which need to call a
macro, but the macro code needs to be based on the row in which the
button was pressed. Is there a good way of finding out the current
row. Activecell doesn't change when you press the button.

I know I can in each of the click events of the buttons call the macro
and pass in an argument for the row number. Just thought there was a
better way.

I am happy to use labels, autoshapes or buttons if this affects a
suggestion.

Many thanks

Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Lots of similar buttons need to call a macro but need to find out

Thanks for that. That's what I've done. I done the buttons as labels,
and then on the click event call the macro passing in the row number.

Cheers mate. Happy New Year to you!



On 7 Jan, 11:28, Joel wrote:
Buttons are part of controls which are really shapes. *Shapes do not have
rows and columns but are positions by the left and top properties which are
in pixels. *Cell also have Top and Left properties which can be used to
position shapes.

In this case I recommend hard coding the row number. *Each button will have
its own click event and put the row number in the click function. *You can
have each of the click events call a common routine like below

Private Sub OptionButton1_Click()
MyRow = 5
call commmonbutton(MyRow)
End Sub
Private Sub OptionButton1_Click()
MyRow = 6
call commmonbutton(MyRow)
End Sub
Private Sub OptionButton1_Click()
MyRow = 7
call commmonbutton(MyRow)
End Sub
sub commmonbutton(MyRow as Integer)
* 'put common code here
end sub



"Guabble" wrote:
Hi


In my spreadsheet I've got about 20 buttons which need to call a
macro, but the macro code needs to be based on the row in which the
button was pressed. *Is there a good way of finding out the current
row. *Activecell doesn't change when you press the button.


I know I can in each of the click events of the buttons call the macro
and pass in an argument for the row number. *Just thought there was a
better way.


I am happy to use labels, autoshapes or buttons if this affects a
suggestion.


Many thanks


Mike- Hide quoted text -


- Show quoted text -


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
Macro button gets bigger when clicked Snowskier Excel Discussion (Misc queries) 1 May 27th 10 09:36 PM
Change Macro button color after clicked Cong Nguyen Excel Discussion (Misc queries) 2 November 30th 07 02:55 PM
Get Button Info/Location in when its clicked and pass to macro [email protected] Excel Programming 0 July 24th 07 10:23 PM
Pause macro, add form button to sheet, continue macro when button clicked! Flystar[_15_] Excel Programming 1 May 26th 04 09:45 AM
How to end macro on inital active worksheet containing macro button that was clicked Silverhawk1 Excel Programming 2 May 14th 04 03:58 PM


All times are GMT +1. The time now is 11:57 PM.

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

About Us

"It's about Microsoft Excel"