DixiePiper
New Member
- Joined
- Oct 19, 2015
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
Is it possible to loop through a series of textboxes to create an array in a specific order?
In a userform, I have 17 textboxes named "txtG1" through "txtG17". I would like to loop through and build an array to pass to the workbook vs. passing each value independently. The code below loops through and passes the values but the order is wrong. I'm not sure what I need to do. I'm using Excel 2013 in a Windows 10 OS.
The result is that 17 values get pasted into column D, starting at D28 but the order is random. I need the array to be sequential from 1 through 17 so everything matches up.
I have to do this for two MultiPage pages for a total of 34. As such, I'd prefer to loop it. That and it helps me learn
Thanks in advance for any assistance.
In a userform, I have 17 textboxes named "txtG1" through "txtG17". I would like to loop through and build an array to pass to the workbook vs. passing each value independently. The code below loops through and passes the values but the order is wrong. I'm not sure what I need to do. I'm using Excel 2013 in a Windows 10 OS.
Code:
For Each ctrl In Me.mpData.Pages(2).Controls
Debug.Print TypeName(ctrl)
If TypeOf ctrl Is MSForms.TextBox Then
i = i + 1
ReDim Preserve onPct(1 To i)
onPct(i) = ctrl.Value
End If
Next ctrl
Set destOn = data.Range("D28")
Set destOn = destOn.Resize(UBound(onPct), 1)
destOn.Value = Application.Transpose(onPct)
The result is that 17 values get pasted into column D, starting at D28 but the order is random. I need the array to be sequential from 1 through 17 so everything matches up.
I have to do this for two MultiPage pages for a total of 34. As such, I'd prefer to loop it. That and it helps me learn
Thanks in advance for any assistance.