![]() |
VBA forms in excel
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. |
VBA forms in excel
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 |
VBA forms in excel
By Field, do you mean Text Box, Label, List Box, ComboBox ? Not familiar
with what a field is. "tcassio" wrote in message ... 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. |
All times are GMT +1. The time now is 01:43 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com