I am working in Excel 2010, developing a user form for data entry into a spreadsheet (we don't trust every end user to enter their data correctly in an open spreadsheet).
Currently, each textbox is named txtDataVal1 to N, with the number incrementing with each new box, and the following code is used to move data from textbox to spreadsheet:
'intRowSelect is given a value elsewhere, by the user's list box selection
Cells(intRowSelect, 2).Value = txtDataVal1.Value
Cells(intRowSelect, 3).Value = txtDataVal2.Value
....
Cells(intRowSelect, 20).Value = txtDataVal20.value
My question: Is there a way to write a simple loop to increment the numeric value at the end of txtDataVal, so I don't have 100+ lines of the bulky code above?
For example (I know this is a non-functional example, consider it pseudo code):
Dim i as Integer
Dim intColumnSelect as Integer
intColumnSelect = 1
i = 1
Do While i < intColumnSelect
intColumnSelect = intColumnSelect + 1
Cells(intRowSelect, intColumnSelect).Value = "txtDataVal" + i.Value
i = i + 1
Loop