Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Command button

Hiya all!

Is it possible to chnage the name of a command button to something thats in
a cell? example. I have a cell with a product name in it but this name
needs to be the name of the command button so you know what button your
pressing, but as this product name changes I need the name of the button to
change too without doing it manually.

Is this possible?


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 080108-0, 08/01/2008
Tested on: 09/01/2008 08:26:41
avast! - copyright (c) 1988-2008 ALWIL Software.
http://www.avast.com



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Command button

Private prev As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Buttons(prev).Name = .Value
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count 1 Then Exit Sub
prev = Target.Value
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Steve" wrote in message
...
Hiya all!

Is it possible to chnage the name of a command button to something thats
in
a cell? example. I have a cell with a product name in it but this name
needs to be the name of the command button so you know what button your
pressing, but as this product name changes I need the name of the button
to
change too without doing it manually.

Is this possible?


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 080108-0, 08/01/2008
Tested on: 09/01/2008 08:26:41
avast! - copyright (c) 1988-2008 ALWIL Software.
http://www.avast.com





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Command button

If I understand what you want correctly, I think this code will work for you...

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then CommandButton1.Caption = Target.Value
End Sub

Note: This assume the Command Button is an ActiveX one (that is, **not** from the Forms toolbar).

Change the "$A$1" to whatever cell address your product name is in... just make sure to use an absolute address (that is, with the $ signs as shown).

Rick


"Steve" wrote in message ...
Hiya all!

Is it possible to chnage the name of a command button to something thats in
a cell? example. I have a cell with a product name in it but this name
needs to be the name of the command button so you know what button your
pressing, but as this product name changes I need the name of the button to
change too without doing it manually.

Is this possible?


---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 080108-0, 08/01/2008
Tested on: 09/01/2008 08:26:41
avast! - copyright (c) 1988-2008 ALWIL Software.
http://www.avast.com



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
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
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
Command Button vs Control Button RGibson Excel Programming 1 October 14th 03 02:24 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 09:41 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"