From: tcassio on
I use forms for data input in excel. I have a for named test. I have 10
fields on the form named t1 thru t10. Currently when I open the form I get
data from a sheet and put it in the field names using:
test.t1.value=sheetname.range("H8"). using this method I have to create 10
lines of code to populate the ten fields. How can I use a for next loop to
change the field name in test.t1.value while stepping through the loop ie;
t1, t2, t3 ect.
From: Dave Peterson on
You didn't share how you loop through the cells. So I used A1 to A3 in my
tests.

You'll have to change the name of the textbox, too.

Option Explicit
Private Sub UserForm_Initialize()
Dim iCtr As Long

For iCtr = 1 To 3 '10 for you
Me.Controls("textbox" & iCtr).Value _
= ActiveSheet.Cells(iCtr, "A").Text
Next iCtr

End Sub

tcassio wrote:
>
> I use forms for data input in excel. I have a for named test. I have 10
> fields on the form named t1 thru t10. Currently when I open the form I get
> data from a sheet and put it in the field names using:
> test.t1.value=sheetname.range("H8"). using this method I have to create 10
> lines of code to populate the ten fields. How can I use a for next loop to
> change the field name in test.t1.value while stepping through the loop ie;
> t1, t2, t3 ect.

--

Dave Peterson
From: JLGWhiz on
By Field, do you mean Text Box, Label, List Box, ComboBox ? Not familiar
with what a field is.


"tcassio" <tcassio(a)discussions.microsoft.com> wrote in message
news:A0FAC862-F6D4-4DAF-8B89-4B4865048380(a)microsoft.com...
>I use forms for data input in excel. I have a for named test. I have 10
> fields on the form named t1 thru t10. Currently when I open the form I
> get
> data from a sheet and put it in the field names using:
> test.t1.value=sheetname.range("H8"). using this method I have to create
> 10
> lines of code to populate the ten fields. How can I use a for next loop
> to
> change the field name in test.t1.value while stepping through the loop ie;
> t1, t2, t3 ect.