This is what I came up with, although the code doesn't work...The NumElements
doesn't make any sense at all, since this is a multi-dimensional array. I
guess it shows better what I'm trying to do, though.
'Populate Mode arrays with data to perform calculations
ReDim arrMode1(1 To LastRow, 1 To 100, 1 To 5)
ReDim arrMode2(1 To LastRow, 1 To 100, 1 To 5)
ReDim arrMode3(1 To LastRow, 1 To 100, 1 To 5)
ReDim arrMode4(1 To LastRow, 1 To 100, 1 To 5)
CountCycle = 0
For j = 8 To LastRow
If arrLabel(j) = "Mode 1" Then
If Not arrLabel(j - 1) = "Mode 1" Then
CountCycle = CountCycle + 1
Count1 = 1
Count2 = 0
Count3 = 0
Count4 = 0
Else
End If
arrMode1(CountCycle, Count1, 1) = arrBedT(j)
arrMode1(CountCycle, Count1, 2) = arrInletT(j)
arrMode1(CountCycle, Count1, 3) = arrRUEGO(j)
ElseIf arrLabel(j) = "Mode 2" Then
Count2 = Count2 + 1
arrMode2(CountCycle, Count2, 1) = arrBedT(j)
arrMode2(CountCycle, Count2, 2) = arrFUEGO(j)
arrMode2(CountCycle, Count2, 3) = arrRUEGO(j)
ElseIf arrLabel(j) = "Mode 3" Then
Count3 = Count3 + 1
arrMode3(CountCycle, Count3, 1) = arrBedT(j)
arrMode3(CountCycle, Count3, 2) = arrRUEGO(j)
arrMode3(CountCycle, Count3, 3) = arrFUEGO(j)
arrMode3(CountCycle, Count3, 4) = arrOxygen(j)
ElseIf arrLabel(j) = "Mode 4" Then
Count4 = Count4 + 1
arrMode4(CountCycle, Count4, 1) = arrTime(j)
arrMode4(CountCycle, Count4, 2) = arrBedT(j)
arrMode4(CountCycle, Count4, 3) = arrRUEGO(j)
arrMode4(CountCycle, Count4, 4) = arrOxygen(j)
Else
End If
Next j
''''''''''''''''''''''''''''''''
'Do calculations on new arrays '
''''''''''''''''''''''''''''''''
For i = 1 To Cycles
'Time at end of Mode 4
N = NumElements(arrMode4, 2)
arrValues(i, 1) = arrMode4(i, N, 1)
'Average Control Oxygen for Modes 3 and 4 - 5 sec after mode 3 begins
SumOxygen = 0
N = NumElements(arrMode3, 2)
M = NumElements(arrMode4, 2)
For j = 5 To N
SumOxygen = SumOxygen + arrMode3(i, j, 4)
Next j
For k = 1 To M
SumOxygen = SumOxygen + arrMode4(i, k, 4)
Next k
arrValues(i, 2) = SumOxygen / (N + M - 5)
'Front UEGO averaged for Mode 2 and 3 - 3 sec after start of Mode 2
SumFUEGO = 0
N = NumElements(arrMode2, 2)
M = NumElements(arrMode3, 2)
For j = 3 To N
SumFUEGO = SumFUEGO + arrMode2(i, j, 2)
Next j
For k = 1 To M
SumFUEGO = SumFUEGO + arrMode3(i, j, 3)
Next k
arrValues(i, 3) = SumFUEGO / (N + M - 3)
'Inlet Temp is average temperature at mode 1 - 10 last seconds
averaged
SumInletTemp = 0
N = NumElements(arrMode1, 2)
For j = (N - 10) To N
SumInletTemp = SumInletTemp + arrMode1(i, j, 2)
Next j
arrValues(i, 4) = SumInletTemp / 10
'T Max Bed T for all modes
M = NumElements(arrMode1, 2)
N = NumElements(arrMode2, 2)
O = NumElements(arrMode3, 2)
P = NumElements(arrMode4, 2)
MaxValue = 0
For j = 1 To M
If arrMode1(i, j, 1) > MaxValue Then
MaxValue = arrMode1(i, j, 1)
End If
Next j
For j = 1 To N
If arrMode2(i, j, 1) > MaxValue Then
MaxValue = arrMode2(i, j, 1)
End If
Next j
For j = 1 To O
If arrMode3(i, j, 1) > MaxValue Then
MaxValue = arrMode3(i, j, 1)
End If
Next j
For j = 1 To P
If arrMode4(i, j, 1) > MaxValue Then
MaxValue = arrMode4(i, j, 1)
End If
Next j
arrValues(i, 5) = MaxValue
'RUEGO peak during Modes 2 and 3
M = NumElements(arrMode2, 2)
N = NumElements(arrMode3, 2)
MaxValue = 0
For j = 1 To M
If arrMode2(i, j, 3) > MaxValue Then
MaxValue = arrMode2(i, j, 3)
End If
Next j
For j = 1 To N
If arrMode3(i, j, 2) > MaxValue Then
MaxValue = arrMode3(i, j, 2)
End If
Next j
arrValues(i, 6) = MaxValue
'R UEGO peak during Modes 4 and the next cycle's 1
M = NumElements(arrMode4, 2)
N = NumElements(arrMode1, 2)
MaxValue = 0
For j = 1 To M
If arrMode4(i, j, 3) > MaxValue Then
MaxValue = arrMode4(i, j, 3)
End If
Next j
For j = 1 To N
If arrMode1(i + 1, j, 3) > MaxValue Then
MaxValue = arrMode1(i + 1, j, 3)
End If
Next j
arrValues(i, 7) = MaxValue
ActiveSheet.Range("Y9:AF" & Cycles + 8).Value = arrValues
Next