The following code fails when I set the upper range of the For Next loop to any number greater than 16. The error: "Run-time error '9': Subscript out of range". The statement that it throws the error on is:
If Vol(i, 1) <> OldVol(i, 1) Then
It works fine for any upper range up to and including 16; but 17 or greater throws the error.
Any help appreciated.
Code Module:
Dim NewVol As Variant
Dim OldVol As Variant
Dim Vol As Variant
Dim RT As Variant
Dim BSRT As Variant
Dim ASRT As Variant
Dim BSize As Variant
Dim ASize As Variant
Dim Start As Variant
Sub Update()
'OldVol = Range("ab55:ab57").Value
'NewVol = Range("ab55:ab57").Value
BSize = Range("n55:n70").Value
ASize = Range("q55:q70").Value
BSRT = Range("ad55:ad70").Value
ASRT = Range("ae55:ae70").Value
Vol = Range("z55:z70").Value
If Start = 0 Then
Exit Sub
End If
'if TimeValue("00:00:08")
Range("ad54").Select
For i = 1 To 16
If Vol(i, 1) <> OldVol(i, 1) Then
BSRT(i, 1) = BSize(i, 1) + BSRT(i, 1)
ActiveCell.offset(i, 0).Value = BSRT(i, 1)
ASRT(i, 1) = ASize(i, 1) + ASRT(i, 1)
ActiveCell.offset(i, 1).Value = ASRT(i, 1)
OldVol(i, 1) = Vol(i, 1)
End If
Next
ActiveCell.offset(-4, 0).Value = ActiveCell.offset(-4, 0).Value + 1
Application.OnTime Now + TimeValue("00:00:01"), "Update"
End Sub

For Next stops at 16
cplusplus1
OldVol = Range("ab55:ab57").Value - Array OldVol contains 3 elements.
Vol = Range("z55:z70").Value - Array Vol contains 16 elements
Trying to read/write an array element (4 in OldVol & 17 in Vol) greater than the number of elements in the array will give the Subscript out of range error.
Doug DeBug