LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 155
Default Command Button Naming

Thank you Basilisk
I can't thank you enough... It worked like a charm :)
Kind Regards
Tanya

"Basilisk96" wrote:

Tanya wrote:
Basilisk you mentioned in an earlier post, that you would be able to simplify
the code so that I could use it with all 10 sheets and commandbuttons? Would
you mind helping me with this please?
Many thanks
Tanya


A few small changes and a loop is all that it takes.
The following code is working for me. I have set up two buttons on
Sheet3, controlled by Sheet1!B2 and Sheet2!C5, respectively. I
believe you have about 10 buttons, so change the constant accordingly,
and add the appropriate button definitions to match. If you have a
statement "Option Base 1" somewhere in your project code, then add 1
to the index of arr() inside the loop.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
Const BUTTON_COUNT = 2 'CHANGE TO NUMBER OF YOUR BUTTONS
Const SHEET_WITH_BUTTONS = "Sheet3" 'NAME OF SHEET CONTAINING
BUTTONS

Dim ButtonDefs() As Variant
ReDim ButtonDefs(0 To BUTTON_COUNT - 1)

' START OF BUTTON DEFINITIONS
'Each array is three strings:
'Name of change sheet, change cell address, associated button name
ButtonDefs(0) = Array("Sheet1", "B2", "CommandButton1")
ButtonDefs(1) = Array("Sheet2", "C5", "CommandButton2")
'
'...CONTINUE THESE DEFINITIONS AS NEEDED...
' END OF BUTTON DEFINITIONS

Dim arr As Variant
For Each arr In ButtonDefs
'NOTE: the following assumes Option Base 0 (the default)
swcc = arr(0) 'sheet with change cell
cca = arr(1) 'change cell address
bn = arr(2) 'button name
If StrComp(Sh.Name, swcc, vbTextCompare) = 0 Then
If Target = Me.Worksheets(swcc).Range(cca) Then
Me.Worksheets(SHEET_WITH_BUTTONS).OLEObjects(bn). _
Object.Caption = Target.Text
End If
End If
Next
End Sub

That's about it! Hope it works for you too.

Cheers,
-Basilisk96

 
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
Wanting to Create A Command Button Command bumper338 Excel Programming 3 May 7th 07 06:53 PM
VB's Command Button vs Form's Command Button Ronald Dodge Excel Programming 3 May 24th 06 02:23 PM
Naming command buttons on a UserForm Casey[_65_] Excel Programming 3 April 7th 06 04:47 PM
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 03:07 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"