ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Command button (https://www.excelbanter.com/excel-programming/403900-command-button.html)

Steve[_98_]

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




Bob Phillips

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






Rick Rothstein \(MVP - VB\)

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





All times are GMT +1. The time now is 01:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com