Incrementing a variable name in For Loop

nbuk

New Member
Joined
Jun 25, 2010
Messages
30
I have a userform with 11 TextBoxes for users to enter in various downtime categories in minutes (integer value). They are tbD1, tbD2, ..., tbD11

What I want to do is loop through the inputs to ensure that they entered a value in a certain range. Here is what I have so far:

Code:
    Dim DTsum As Integer 'sum of all entered downtime
    Dim ShiftLength As Integer 'max shift length
    DTsum = 0
    ShiftLength = Sheet3.Range("D2").Value
    
    'Check that the downtime doesn't exceed the maximum possible shift length
    For i = 1 To 11
        DTsum = DTsum + Me.tbD(i)
        If Me.tbD(i) > ShiftLength Or Me.tbD(i) < 0 Or DTsum > ShiftLength Then
            MsgBox ("Please ensure that the entered downtime doesn't exceed the maximum shift length.")
        End If
    Next i

"Me.tbD(i)" is what gives me an error. I am not sure if there is any other syntax that I can use to loop through these variables?

Any help is greatly appreciated! Thanks!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I know this is a little primitive but as a noob what i would do would be to check each textbox individually....as you only have 11. That is if you are in a hurry. And your welcome.
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,273
Members
448,559
Latest member
MrPJ_Harper

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