PDA

View Full Version : How to change 40 label captions



fogman
07-19-2006, 06:24 PM
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.

malik641
07-19-2006, 07:44 PM
Hey Fogman, and welcome.

Not sure what you want exactly....

Small example:

Me.txt_1.Text = "fogman"

Or from Sheet1

Me.txt_1.Text = Sheets("Sheet1").Range("A1")

HTH

matthewspatrick
07-19-2006, 08:25 PM
fogman,

Please elaborate on what you're trying to do.

fogman
07-19-2006, 08:58 PM
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.

fogman
07-19-2006, 10:12 PM
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

mdmackillop
07-19-2006, 11:31 PM
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.


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

mdmackillop
07-19-2006, 11:36 PM
Hi Fogman,
I edited your question title to correct your error.