Joe4
MrExcel MVP, Junior Admin
- Joined
- Aug 1, 2002
- Messages
- 74,817
- Office Version
- 365
- Platform
- Windows
On a user form, I have 30 text boxes named txtFund1 through txtFund30. In VBA, I am trying to access these boxes to initialize them, and update values on my Excel spreadsheet with these values.
I can to do all this pretty easily by writing a line for each inidividual text box. However, I want to be more efficient and use a loop. However, I can not get it to work. Here is my code to initialize the values, that isn't working:
What do I need to do to be able to loop through all 30 text boxes? Keep in mind that there are also other text boxes on my form, so I can't just through all text boxes on the form.
I can to do all this pretty easily by writing a line for each inidividual text box. However, I want to be more efficient and use a loop. However, I can not get it to work. Here is my code to initialize the values, that isn't working:
Code:
Dim i As Integer
Dim MyTextBox
For i = 1 To 30
MyTextBox = txtFund & i
MyTextBox.Value = ""
Next i
What do I need to do to be able to loop through all 30 text boxes? Keep in mind that there are also other text boxes on my form, so I can't just through all text boxes on the form.