T
Tanya
Hi
Is it possible to have the description/label of a command button updated by
the title in a sheet cell?
cheers
Tanya
Is it possible to have the description/label of a command button updated by
the title in a sheet cell?
cheers
Tanya
Hi
Is it possible to have the description/label of a command button updated by
the title in a sheet cell?
cheers
Tanya
goes in Sheet1; and you needPrivate Sub Worksheet_Change(ByVal Target As Range)
Tanya said:I did what you suggested but must be missing something.
Private Sub Worksheet_Change(ByVal Target As Range)
'Target Address is on a separate sheet, I don't think I have done this
correctly
If Target.Address = "Sheet1!B2" Then
CommandButton1.Caption = Target.Value
End If
End Sub
I guess it sounds like a weird thing to want to do, but on my startup sheet
I have a number of command buttons each linked to a separate sheet [classe
lists]
Dave D-C said:[12:48AM!?]
Thegoes in Sheet1; and you needPrivate Sub Worksheet_Change(ByVal Target As Range)
Sheets("sheetX").CommandButton1.Caption = Target.Value
D-C Dave
Tanya said:I did what you suggested but must be missing something.
Private Sub Worksheet_Change(ByVal Target As Range)
'Target Address is on a separate sheet, I don't think I have done this
correctly
If Target.Address = "Sheet1!B2" Then
CommandButton1.Caption = Target.Value
End If
End Sub
I guess it sounds like a weird thing to want to do, but on my startup sheet
I have a number of command buttons each linked to a separate sheet [classe
lists]
Hi Dave
I'm still missing something, when I try to run this macro it brings up a
dialogue box which wants choose a macro to run.
Sheet 33 has the commandButton1 which has the following code:
Private Sub CommandButton1_Click()
'Unprotect workbook
UnProtect_Workbook
'Show Task Weights
Sheets("1").Visible = True
Sheets("1").Select
'Protect workbook
Protect_Workbook
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("sheet1").CommandButton1.Caption = Target.Value
If Target.Address = "B2" Then
CommandButton1.Caption = Target.Value
End If
End Sub
Thanks
Tanya
Dave D-C said:[12:48AM!?]
Thegoes in Sheet1; and you needPrivate Sub Worksheet_Change(ByVal Target As Range)
Sheets("sheetX").CommandButton1.Caption = Target.Value
D-C DaveTanya said:I did what you suggested but must be missing something.
Private Sub Worksheet_Change(ByVal Target As Range)
'Target Address is on a separate sheet, I don't think I have done this
correctly
If Target.Address = "Sheet1!B2" Then
CommandButton1.Caption = Target.Value
End If
End Sub
I guess it sounds like a weird thing to want to do, but on my staHrtup sheet
I have a number of command buttons each linked to a separate sheet [classe
lists]
:
Of course.
Let's say your title cell is A1, and your command button is named in
code as CommandButton1. In the source code of the sheet object, enter
this code in the Worksheet_Change event:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
CommandButton1.Caption = Target.Value
End If
End Sub
Hi
Is it possible to have the description/label of a command button updated by
the title in a sheet cell?
cheers
Tanya
Then when you enter something into sheet1 A1,Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Sheets("Sheet33").CommandButton1.Caption = Target.Value
End If
End Sub
dan dungan said:I'm trying to reproduce your problem, but I'm unable to.
Const SHEET_WITH_CHANGE_CELL = "Sheet1" '<<< NAME OF SHEET WITH CELL
An earlier post appeared to work, however I found that when I edited other
cells in the worksheet the commandbutton would be updated, no idea how when I
had specified the target cell
YES you are correct <<<<<<Basilisk96 said:Am I correct to assume that the sheet tab of your Sheet1 object is
named "1"?
If so, then trying to index it by "Sheet1" will raise a "Index out of
bounds" error because that tab doesn't exist.
I like Chip's suggestion, because it paves the way for a systematic
approach to your problem: with a loop construct and a little more
code, you can update all the ten class buttons under one procedure
call.
I'd like to correct myself on my first suggestion, though. I think
it's much more robust not to use the address property for ID directly
in the way I showed it originally. A better way could be to use the
Range property:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target = Range("B2") Then
Sheets("Sheet33").CommandButton1.Caption = Target.Value
End If
End Sub
All I know is that when I worked in the rest of the workbook, i.e. insertThis eliminates the hassle of "$B$2" vs. "B2" comparison failures.
The Target.Address property always returns an absolute address with
the $ signs, whereas Range can take a wider variety of inputs.
This doesn't make sense. How do you know that the button's caption
got updated with the target cell's text, unless you changed the target
cell's contents (which would trigger the caption change as expected) ?
I haven't had this error? <<<<<<<<
Chips code didn't appear to work. I wondered if I had placed the code under
the incorrect sheet?
I tried this and again not working for me. Note I placed the code against
sheet1 labeled '1' <<<<<<<<<<
All I know is that when I worked in the rest of the workbook, i.e. insert
column the macro ran and changed the commandbutton1 caption, relevant to the
contents in a cell other than B2?? I have no idea why this was happening
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.