PC Review


Reply
Thread Tools Rate Thread

Changing the text of a label on a Userform

 
 
Robert Crandal
Guest
Posts: n/a
 
      7th Dec 2009
My userform contains one label control that contain a
text caption. The problem is, I want the text caption
to mirror the contents of cell "A1" at all times.

So, when the userform is loaded, I want it to immediately
read the value from cell "A1" and store it in my label's
caption. Then, every time someone changes the contents of
cell "A1" I want my label to immediately detect the change
and re-load the text from cell "A1" onto the label.

What would be a good way to implement this?? Would it
involve using a combination of Userform_Initialize()
and Worksheet_Change()?? Does anyone have any code
examples?

thank you!


 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      7th Dec 2009
Yes, you would use the UserForm's Initialize event and the Worksheet's
Change event. Of course, this assumes you are showing the UserForm as
non-modal; that is, when executing the command to show the UserForm, you do
so by specifying the optional vbModeless argument to the Show method like
this...

UserForm1.Show vbModeless

Here is the other code you will need (read the comments)...

' Put this in the UserForm's code window
Private Sub UserForm_Initialize()
Label1.Caption = Worksheets("Sheet1").Range("A1").Value
End Sub

' Put this in the worksheet's code window
Private Sub Worksheet_Change(ByVal Target As Range)
UserForm1.Label1.Caption = Range("A1").Value
End Sub

Note that I used the default names for the UserForm and Label and assumed
that A1 was on Sheet1 (change these values in the code above to match your
actual conditions).

--
Rick (MVP - Excel)


"Robert Crandal" <(E-Mail Removed)> wrote in message
news:9I2Tm.60844$%(E-Mail Removed)...
> My userform contains one label control that contain a
> text caption. The problem is, I want the text caption
> to mirror the contents of cell "A1" at all times.
>
> So, when the userform is loaded, I want it to immediately
> read the value from cell "A1" and store it in my label's
> caption. Then, every time someone changes the contents of
> cell "A1" I want my label to immediately detect the change
> and re-load the text from cell "A1" onto the label.
>
> What would be a good way to implement this?? Would it
> involve using a combination of Userform_Initialize()
> and Worksheet_Change()?? Does anyone have any code
> examples?
>
> thank you!
>
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set Userform label text if form is not loaded??? Robert Crandal Microsoft Excel Programming 3 21st Dec 2009 07:34 PM
Changing the label on text box =?Utf-8?B?R3JlZyBG?= Microsoft Access 2 16th Sep 2006 06:36 AM
Changing text size in option buttons on a userform =?Utf-8?B?Q29lbiBCdXJnZXI=?= Microsoft Excel Programming 1 7th Aug 2005 09:04 AM
Userform - Formating Text in a Label =?Utf-8?B?VEVCMg==?= Microsoft Excel Programming 4 21st Apr 2005 09:23 PM
changing selected label on userform w/ a variable mike k Microsoft Excel Programming 1 19th Feb 2004 01:48 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:50 AM.