Command button

S

Steve

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
 
B

Bob Phillips

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)
 
R

Rick Rothstein \(MVP - VB\)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Spin button 2
Merging 1
Auto insert 2
How do you hide ..... 2
reset a cell 5
Hidding buttons 3
Transparent button 5
Locking Cells 1

Top