Dynamic macro button label

Q45

New Member
Joined
Feb 17, 2002
Messages
32
Is there a way to make the label of a macro button dynamic so that it is labeled as the results of a specific cell. (i.e., If I type the name of a person into a cell, can I have a macro button labeled as the same name as the contents of that cell, even if I change the name?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Assuming your button is called CommandButton1 and the cell you want the caption to appear in is A1 try this:-

Right click the worksheet tab and choose View Code. Then try this:

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

HTH,
D
 
Upvote 0
I've tried that every possible and I can't get it to work. Is there anything more specific I could be looking at?
 
Upvote 0
dk is right on. Make sure that you have the code in the Worksheet object, and not in a module. Follow his instructions to the "T".

What does that mean, anyway, "To the T"? Anyone?

-Russell
This message was edited by Russell Hauf on 2002-02-19 16:21
 
Upvote 0
Follow his instructions to the "T".
What does that mean, anyway, "To the T"? Anyone?
`````````````
old latin convertion for"letter" but cant remember the T word now... latin has all but dided out now bar doctors and legal peoples

Rdgs
Jack
 
Upvote 0
Am curious, can a macro be assigned to that button BUT the macro assigned depends on the name currently on the button? If possible, would the button name and macro have to be the same? Just curious.

THANKS!
 
Upvote 0
On 2002-04-10 13:49, Cosmos75 wrote:
Am curious, can a macro be assigned to that button BUT the macro assigned depends on the name currently on the button? If possible, would the button name and macro have to be the same? Just curious.

THANKS!

Hi,

It can be done, but the trigger mechanism to change the caption would/should also trigger the procedure to run, like the following pseudo code.

If range1 >10 then
button.caption = "Forget this"
Call "forget_this_macro"
Else if ....

would be the most frequent route. You could test the caption, as you wish to do:

If button.caption = "Run Me" then
"Run_Me"
Else
"Run_something_else"
End if

It just seems backward to me.

HTH,
Jay
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top