Hello,
I was wondering if it's possible to create a For Next loop with uneven intervals as described below as opposed to creating many different loops.
ie.
For i = (1 To 50), (100-150), (200-250)
..........
Next
Hello,
I was wondering if it's possible to create a For Next loop with uneven intervals as described below as opposed to creating many different loops.
ie.
For i = (1 To 50), (100-150), (200-250)
..........
Next
Hard to tell exactly what you are trying to do, but could you use
For i = a to b and set the values of a to b accordingly?
Thank you for your response. I'll try to explain a little more clearly.
I have an array of 3650 values corresponding to 10 years of daily information. I want to place values from 12 worksheet cells into the array. For example lets say I have a counter i for the array. I want the first value from the worksheet cell to be placed in the array i values of 1-30, 365-395, 730-760, 1095-1125 and so on. I was wondering if I could use a one loop to place the values into the array as opposed to a loop for each interval.
I hope this description makes it easier to understand.
Thanks again,
dannyo
thank you tinyjack,
I just read your response and that will work.
Cheers,
dannyo
I suspect this is very similar to other answers that will be posted in the meantime, but here goes:
Sub MultiLoops()
Dim avarLoopStart As Variant, avarLoopEnd As Variant
Dim a As Long, b As Long
avarLoopStart = Array(1, 100, 200)
avarLoopEnd = Array(50, 150, 250)
For a = 0 To UBound(avarLoopStart)
For b = avarLoopStart(a) To avarLoopEnd(a)
' Your calculations here
Next b
Next a
End Sub
Display More
Hope this helps.
Regards,
Batman.
Don’t have an account yet? Register yourself now and be a part of our community!