1

I have form inputs called "text1, text2, text2..." and I have an array of strings to fill the inputs with...

What I want is this....

text1.Value = Invoice.input(1)
text2.Value = Invoice.input(2)
text3.Value = Invoice.input(3)

but this seems like a lot of typing for something I know can be done with a simple for loop..

for loop = 1 To loop = 50 
 text+i.Value = Invoice.input(i)
next loop 

how can I use text+i to call my var which is actually called text1?

When doing a Google search a few people said to use the Eval() function but this didn't work for me.

Thanks.

1 Answer 1

5

This should do it: (or at least help)

Sub ControlName()
    Dim i As Long
    For i = 1 To 50
        UserForm1.Controls("text" & i).Value = Invoice.input(i)
    Next
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Brilliant thank you!! UserForm1.Controls("text" & var) works perfectly! been looking for this for some time!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.