Results 1 to 3 of 3

Thread: UserForm Label

  1. #1
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    UserForm Label

    I have a label on a UserForm that is supposed to display the contents of a cell within the spreadsheet. When I go into VBA edit mode and open the userform, then double click the actual label to get to the code, this is what I have:

    Private Sub dDate_Click()

    Me.dDate.Caption = Sheet2.Range("J4").Value
    End Sub

    dDate is the label. The problem is I can only get the label to display "J4" by clicking the label. I want it to be automatic, when the userform is opened. Can someone tell me what I'm doing wrong?
    - Ricky

  2. #2
    Lounger
    Join Date
    May 2001
    Location
    the Netherlands
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: UserForm Label

    Your line of code is correct, the problem is that it is in an event procedure of the label: dDate_Click(). If you want the code to run when the form is "opened" it should be in the initialize event of the User Form.
    To get it there, right click the User Form and select display the code. Use the left dropdown box at the top to select UserForm; in the other box select the event "Initialize". Put your line of code between the lines generated by the VB Editor.

    Ingrid

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Dallas, Texas, USA
    Posts
    1,680
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: UserForm Label

    Ingrid - Thank you, that worked just like it was supposed to.
    - Ricky

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •