As ChrisScott recommended, you need to add Preserve.
When you redimension an array, memory for the array's new size is allocated. This is NOT the same section of memory as where the array was being stored prior to the redim.
After the allocation, the array is adjusted to point to the new memory (which is, of course, blank). If you use Preserve, the data from the old memory is copied to the new meory.
This slows things down a lot. If you can, you should try to set the array size to as large of a size as you will need, and keep track of how much of it has been filled in either one of the elements, or a separate variable.
k(0) = a
k(1) = b
k(2) = c
k(3) = d
ReDim feasible(4, 3)
For j = 0 To 3
n = k(j)
For i = 0 To n - 1
feasible(j, i) = Sheet1.Cells(3, 2 + j ) + i * (1 / 24)
If feasible(j, i) > 1 Then
feasible(j, i) = feasible(j, i) - 1
' Here I can store the right # in feasible(j, i)
End If
Next i
' Here all numbers in the array become zero
Next j
|