Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default Set Userform label text if form is not loaded???

My userform contains various text label controls which display
the contents of a row of cells. I achieve this with the following code:

Private Sub Worksheet_Change (ByVal Target As Range)
UserForm1.Label1.Caption = Sheet1.Range("A1").Value
UserForm1.Label2.Caption = Sheet1.Range("B1").Value
UserForm1.Label3.Caption = Sheet1.Range("C1").Value
' ....
' etc, etc...
End Sub


I was wondering, is it wise to run the above code even when
my userform is not loaded??? The code above seems to
work fine even when my form is NOT loaded, but I'm worried
that trying to set the text of a label that doesn't exist will
cause bugs later on.


thank you


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Set Userform label text if form is not loaded???

The reason you are not having any problems with your code is because as soon
as you reference a property or method of a UserForm, VB loads that UserForm
into memory (it doesn't show it... it just loads it). If you were to show
your UserForm after doing something to make the Change event fire, I am
pretty sure the UserForm will display with the Label control captions
already filled in.

--
Rick (MVP - Excel)


"Robert Crandal" wrote in message
...
My userform contains various text label controls which display
the contents of a row of cells. I achieve this with the following code:

Private Sub Worksheet_Change (ByVal Target As Range)
UserForm1.Label1.Caption = Sheet1.Range("A1").Value
UserForm1.Label2.Caption = Sheet1.Range("B1").Value
UserForm1.Label3.Caption = Sheet1.Range("C1").Value
' ....
' etc, etc...
End Sub


I was wondering, is it wise to run the above code even when
my userform is not loaded??? The code above seems to
work fine even when my form is NOT loaded, but I'm worried
that trying to set the text of a label that doesn't exist will
cause bugs later on.


thank you



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Set Userform label text if form is not loaded???

As soon as you reference your userform the userform will then be loaded into
memory. It may or may not be a bad thing. I guess it depends on the size
(how much memory the form takes up) of the userform and how strong your
computer is (how much memory it has available). If your not really needing
your userform when your worksheet is changed, I would just put the code you
posted in the userforms Intialize Event. This way when your userform is
shown it will have all your controls set the way you want it.

Private Sub UserForm_Initialize()

Me.Label1.Caption = Sheet1.Range("A1").Value
Me.Label2.Caption = Sheet1.Range("B1").Value
Me.Label3.Caption = Sheet1.Range("C1").Value
' ....
' etc, etc...

End Sub
--
Cheers,
Ryan


"Rick Rothstein" wrote:

The reason you are not having any problems with your code is because as soon
as you reference a property or method of a UserForm, VB loads that UserForm
into memory (it doesn't show it... it just loads it). If you were to show
your UserForm after doing something to make the Change event fire, I am
pretty sure the UserForm will display with the Label control captions
already filled in.

--
Rick (MVP - Excel)


"Robert Crandal" wrote in message
...
My userform contains various text label controls which display
the contents of a row of cells. I achieve this with the following code:

Private Sub Worksheet_Change (ByVal Target As Range)
UserForm1.Label1.Caption = Sheet1.Range("A1").Value
UserForm1.Label2.Caption = Sheet1.Range("B1").Value
UserForm1.Label3.Caption = Sheet1.Range("C1").Value
' ....
' etc, etc...
End Sub


I was wondering, is it wise to run the above code even when
my userform is not loaded??? The code above seems to
work fine even when my form is NOT loaded, but I'm worried
that trying to set the text of a label that doesn't exist will
cause bugs later on.


thank you



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default Set Userform label text if form is not loaded???

As soon as you reference your userform the userform will then be loaded into
memory. It may or may not be a bad thing. I guess it depends on the size
(how much memory the form takes up) of the userform and how strong your
computer is (how much memory it has available). If your not really needing
your userform when your worksheet is changed, I would just put the code you
posted in the userforms Intialize Event. This way when your userform is
shown it will have all your controls set the way you want it.

Private Sub UserForm_Initialize()

Me.Label1.Caption = Sheet1.Range("A1").Value
Me.Label2.Caption = Sheet1.Range("B1").Value
Me.Label3.Caption = Sheet1.Range("C1").Value
' ....
' etc, etc...

End Sub

--
Cheers,
Ryan


"Robert Crandal" wrote:

My userform contains various text label controls which display
the contents of a row of cells. I achieve this with the following code:

Private Sub Worksheet_Change (ByVal Target As Range)
UserForm1.Label1.Caption = Sheet1.Range("A1").Value
UserForm1.Label2.Caption = Sheet1.Range("B1").Value
UserForm1.Label3.Caption = Sheet1.Range("C1").Value
' ....
' etc, etc...
End Sub


I was wondering, is it wise to run the above code even when
my userform is not loaded??? The code above seems to
work fine even when my form is NOT loaded, but I'm worried
that trying to set the text of a label that doesn't exist will
cause bugs later on.


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 text of a label on a Userform Robert Crandal Excel Programming 1 December 7th 09 08:39 AM
Multiple fonts in a VBA UserForm label (to make XL 95 form non-modal) Anthony Berglas Excel Programming 2 August 13th 07 05:37 AM
Userform - Formating Text in a Label TEB2 Excel Programming 4 April 21st 05 09:23 PM
Help! Animated gif-image in form does not show animation when form loaded JoCa Excel Programming 4 September 23rd 04 07:43 PM
Label, Text and Form controls in Excel 97 TomCee Excel Programming 1 April 20th 04 04:52 PM


All times are GMT +1. The time now is 10:05 AM.

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"