return textfrom cell into textbutton/commandbutton

  • Thread starter Thread starter Jonsson
  • Start date Start date
J

Jonsson

Hi all,

Is it possible to return a textvalue from a cell into a
textbutton/commandbutton so that the text in the button changes depending of
what you write in the cell?
If so, how to do it?

Any help is apprecciated!!

//Thomas
 
Hello
Place this in the sheet's code and amend accordingly:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$15" And Target.Value <> "" Then
Me.CommandButton1.Caption = Target.Value
End If
End Sub

HTH
Cordially
Pascal
 
Hi Pascal

Thanks for your answer.

I'm sure the code is okay, but is it something I have to do to get the code
working in my application.
It seems to be some problem, because the macro wont work for me.
My button is'nt a commandButton, it's a textbutton (hope you know what I
mean). Could that be the problem?
 
Where did you get the "textbutton" from:
Forms tool bar
Controls Tool Box
?
Cordially
Pascal
 
Hello
This is what I "feared".
I would personnaly rather recommend you use one of the controls tool box
items instead.
As it will be definitely easier for you to access its properties (Value or
Caption for instance).
In the sample code I provided previously you will note that I am using the
key word "Me" which identifies the worksheet since you are dealing with this
object class when you are in the Worksheet code (right-clicking on the
worksheet tab and selecting view code brings you there)
Using this method will automatically provide access to any property or
object related to the worksheet using the dot (.)
Thus if you have previoulsy created a commandbutton for example (from the
controls tool box) and by default its name will be CommandButton1, if you
use the word Me followed by the dot (ie: Me.) then you will have a pop up
list with all the available items among which you will find the object
"CommandButton1".
Hope this helps you get on further.

Cordially
Pascal
 

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

Back
Top