Consulting

Results 1 to 7 of 7

Thread: How to change 40 label captions

  1. #1

    Unhappy How to change 40 label captions

    Please help.

    I have 40 textbox in a form. Named similar to the following :-

    txt_1 , txt_2 , txt_3 , txt_4 , .........

    the captions will change when a user changes values in Excel fields.

    How can I make their captions change automatically ?

    Thanks very much for your help in advance.

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    Hey Fogman, and welcome.

    Not sure what you want exactly....

    Small example:

    [VBA]Me.txt_1.Text = "fogman"[/VBA]

    Or from Sheet1

    [VBA]Me.txt_1.Text = Sheets("Sheet1").Range("A1")[/VBA]

    HTH




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    fogman,

    Please elaborate on what you're trying to do.
    Regards,

    Patrick

    I wept for myself because I had no PivotTable.

    Then I met a man who had no AutoFilter.

    Microsoft MVP for Excel, 2007 & 2008

  4. #4

    Talking Sorry, my fault.It's Label, not textbox. Sorry

    Please help.

    I have 40 labels in a form. Named similar to the following :-

    lbl_1 , lbl_2 , lbl_3 , lbl_4 , .........

    the captions will change when a user changes values in Excel fields.

    How can I make their captions change automatically ?

    Thanks very much for your help in advance.

  5. #5

    Post Further explain what I'm doing

    In Sheet 1

    range(A1 ) = "ABC"
    range(A2 ) = "DEF"
    range(A3 ) = "GHI"
    .
    .
    .
    .
    .

    The captions of the 40 labels of the form are according to the values of above cells.

    label 1 : lbl_1.caption = range(A1)
    label 2 : lbl_2.caption = range(A2)
    label 3 : lbl_3.caption = range(A3)
    .
    .
    .
    .

    What I did is I type as the above 40 lines in the code page of a form. Can I make it better and shorter ?

    Thanks

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Fogman,
    Welcome to VBAX
    This uses a textbox on the form to change column numbers, and the label captions come from the data in the various columns.

    [vba]
    Private Sub TextBox1_Change()
    If TextBox1 <> "" Then
    For i = 1 To 4
    Me.Controls("label" & i).Caption = Cells(i, TextBox1)
    Next
    End If
    End Sub

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Fogman,
    I edited your question title to correct your error.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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