Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Changing the text of a label on a Userform

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!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Changing the text of a label on a Userform

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the font for part of an axis label, not the whole label. amy45 Charts and Charting in Excel 2 April 5th 23 01:11 PM
Changing label caption in a Userform to an opterator value jumpjump Excel Programming 2 August 25th 05 01:50 AM
Changing text size in option buttons on a userform Coen Burger Excel Programming 1 August 7th 05 09:04 AM
Userform - Formating Text in a Label TEB2 Excel Programming 4 April 21st 05 09:23 PM
changing selected label on userform w/ a variable mike k Excel Programming 1 February 19th 04 01:48 AM


All times are GMT +1. The time now is 06:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"