Loop mulitply textboxes

Celica

New Member
Joined
Jul 6, 2016
Messages
9
Hi Guys
I have 6 textboxes going across and this is repeated 10 times down my userform. The textboxes going across are in chronological order. The row of textboxes will populate when the user selects their choice from a combobox and click on a button. It will populate to the next row of textboxes if another choice is selected. I have written an amateur code and it achieves my purpose, but am not content with it. I was wondering if writing a code to loop the rows of textboxes would be a better approach, and if so, how can I go about it? At the moment I am struggling to understand how “loop“ can do the trick when row one of the first textbox (eg textbox149) is not a sequential number to the textbox directly below it (textbox155) – row 2, see illustration if I’m not making sense?

Textbox149 Textbox150 Textbox151 Textbox152 Textbox153 Textbox154
Textbox155 Textbox156 Textbox157 Textbox158 Textbox159 Textbox160
Textbox161 Textbox162 Textbox163 Textbox164 Textbox165 Textbox166

I also thought I could reference the row1 to textboxes149 to 154, but again I’m unsure how to do this as well. Grateful for any assistance or point of direction. I have considered the code:
Dim x As Integer
For x = 185 To 190
Me.Controls("Textbox" & x).value = ""


But struggle to apply it because each row do not have a sequential number directly below it.

Thanks
Celica

Please find a snapshot of my code if you’re interested:
Private Sub CommandButton3_Click()
Dim nextsub As String
Dim SID As String
Select Case TextBox149.value

Case Is = ""

TextBox149.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 0)
TextBox150.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 1)
TextBox151.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 2)
TextBox152.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 4)
'TextBox77.value = TextBox155.value * TextBox152.value
SID83 = msgbox("Does this support item have the same dates as the support plan", vbYesNo)
If SID83 = vbNo Then
'TextBox180.value = TextBox83.value
UserForm1.TextBox1.value = TextBox83.value
UserForm1.Show
'ED83 = InputBox("Please enter the start date and end date eg.1/03/16 to 30/4/16")

'TextBox180.value = TextBox83.value & " " & "dates are" & " " & ED83
ElseIf SID83 = vbYes Then
End If
Exit Sub
End Select

Select Case TextBox155.value
Case Is = ""
TextBox155.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 0)
TextBox156.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 1)
TextBox157.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 2)
TextBox158.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 4)
'TextBox77.value = TextBox155.value * TextBox152.value
SID153 = msgbox("Does this support item have the same dates as the support plan", vbYesNo)
If SID153 = vbNo Then
'TextBox183.value = TextBox153.value
UserForm1.TextBox1.value = TextBox153.value
UserForm1.Show
'ED153 = InputBox("Please enter the start date and end date eg.1/03/16 to 30/4/16")

'TextBox181.value = TextBox83.value & " " & "dates are" & " " & ED153
ElseIf SID153 = vbYes Then
End If


If TextBox153 = "" Then
GoTo nextsub
ElseIf TextBox153 = TextBox83 Then
msgbox "Warning! You've already selected this support item"

nextsub:
End If
Exit Sub
End Select
Select Case TextBox160.value
Case Is = ""
TextBox160.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 0)
TextBox161.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 1)
TextBox162.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 2)
TextBox163.value = Me.ComboBox14.List(Me.ComboBox14.ListIndex, 4)
'TextBox77.value = TextBox155.value * TextBox152.value
SID160 = msgbox("Does this support item have the same dates as the support plan", vbYesNo)
If SID160 = vbNo Then
'TextBox192.value = TextBox160.value
UserForm1.TextBox1.value = TextBox160.value
UserForm1.Show

' ED160 = InputBox("Please enter the start date and end date eg.1/03/16 to 30/4/16")
' TextBox182.value = "Support Reference" & "-" & TextBox160.value & " " & "dates are" & " " & ED160
ElseIf SID160 = vbYes Then
End If

If TextBox160 = "" Then
GoTo a
ElseIf TextBox160 = TextBox83 Or TextBox160 = TextBox153 Then
msgbox "Warning! You've already selected this support item"

a:
End If
Exit Sub
End Select
.....
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,215,429
Messages
6,124,837
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top