M
Matt S
Hi all! The following code works, but takes forever to finish. The
background is that I have LabView recording data from a reactor that has four
modes. Sometimes the modes don't exactly go as planned, so some seconds are
skipped in a mode. I therefore need to correct the data and correctly label
the modes.
Once the four modes are labeled correctly, I then need to do several
calculations and place the results in a separate table. The problem is that
the data is 50 hours long, so doing the calculations takes at least 5 minutes.
If there is a better way to do this, please point me in the right direction.
Thanks!
Matt
Function Label_Av(Cycles As Variant)
CellsShifted = 0
For i = 1 To Cycles
If Not ActiveCell.Offset(60 * (i - 1), -1).Value = """" Then
'''''''''''''''''
'Label Modes '
'''''''''''''''''
ActiveCell.Range("A" & 60 * (i - 1) + 1 - CellsShifted &
":A" & 60 * (i - 1) + 40 - CellsShifted).Value = "Mode 1"
ActiveCell.Range("A" & 60 * (i - 1) + 41 - CellsShifted &
":A" & 60 * (i - 1) + 46 - CellsShifted).Value = "Mode 2"
ActiveCell.Range("A" & 60 * (i - 1) + 47 - CellsShifted &
":A" & 60 * (i - 1) + 56 - CellsShifted).Value = "Mode 3"
ActiveCell.Range("A" & 60 * (i - 1) + 57 - CellsShifted &
":A" & 60 * (i - 1) + 60 - CellsShifted).Value = "Mode 4"
'Check to see if time values match up to labels and fix if
not correct
Time_Diff = ActiveCell.Offset(60 * (i - 1) + 60 -
CellsShifted, -23).Value - ActiveCell.Offset(60 * (i - 1) + 1 - CellsShifted,
-23).Value
If Not Time_Diff < 60.9 Then '<60.9 because some values
recorded are not exactly 1 second
CellsShifted = CellsShifted + Fix_Time(i)
Else
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Perform calcs on four modes and place in separate table '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Time at end of Mode 4
Range("Y" & i + 9).Value = ActiveCell.Offset(0,
-23).Range("A" & 60 * (i - 1) + 60 - CellsShifted)
'Control Oxygen for Modes 3 and 4 - 5 sec after start of
Mode 3
Range("Z" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -20).Range("A" & 60 * (i - 1) + 47 + 5 - CellsShifted &
":A" & 60 * (i - 1) + 60 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'Front UEGO averaged for Mode 2 and 3 - 3 sec after start of
Mode 2
Range("AA" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -8).Range("A" & 60 * (i - 1) + 41 + 3 - CellsShifted &
":A" & 60 * (i - 1) + 56 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'Inlet Temp is average temperature at mode 1 - 10 last
seconds averaged
Range("AB" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -11).Range("A" & 60 * (i - 1) + 1 + 30 - CellsShifted &
":A" & 60 * (i - 1) + 40 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'Average Bed T for Mode 1 - 10 last seconds
Range("AC" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -10).Range("A" & 60 * (i - 1) + 1 + 30 - CellsShifted &
":A" & 60 * (i - 1) + 40 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'T Max Bed T for all modes
Range("AD" & i + 9).FormulaR1C1 = "=Max(" &
ActiveCell.Offset(0, -10).Range("A" & 60 * (i - 1) + 1 - CellsShifted & ":A"
& 60 * (i - 1) + 60 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'R UEGO peak during Modes 2 and 3
Range("AE" & i + 9).FormulaR1C1 = "=Max(" &
ActiveCell.Offset(0, -6).Range("A" & 60 * (i - 1) + 41 - CellsShifted & ":A"
& 60 * (i - 1) + 56 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'R UEGO peak during Modes 4 and the next cycle's 1
Range("AF" & i + 9).FormulaR1C1 = "=Max(" &
ActiveCell.Offset(0, -6).Range("A" & 60 * (i - 1) + 57 - CellsShifted & ":A"
& 60 * (i - 1) + 60 + 40 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
End If
Next
Label_Av = CellsShifted
End Function
background is that I have LabView recording data from a reactor that has four
modes. Sometimes the modes don't exactly go as planned, so some seconds are
skipped in a mode. I therefore need to correct the data and correctly label
the modes.
Once the four modes are labeled correctly, I then need to do several
calculations and place the results in a separate table. The problem is that
the data is 50 hours long, so doing the calculations takes at least 5 minutes.
If there is a better way to do this, please point me in the right direction.
Thanks!
Matt
Function Label_Av(Cycles As Variant)
CellsShifted = 0
For i = 1 To Cycles
If Not ActiveCell.Offset(60 * (i - 1), -1).Value = """" Then
'''''''''''''''''
'Label Modes '
'''''''''''''''''
ActiveCell.Range("A" & 60 * (i - 1) + 1 - CellsShifted &
":A" & 60 * (i - 1) + 40 - CellsShifted).Value = "Mode 1"
ActiveCell.Range("A" & 60 * (i - 1) + 41 - CellsShifted &
":A" & 60 * (i - 1) + 46 - CellsShifted).Value = "Mode 2"
ActiveCell.Range("A" & 60 * (i - 1) + 47 - CellsShifted &
":A" & 60 * (i - 1) + 56 - CellsShifted).Value = "Mode 3"
ActiveCell.Range("A" & 60 * (i - 1) + 57 - CellsShifted &
":A" & 60 * (i - 1) + 60 - CellsShifted).Value = "Mode 4"
'Check to see if time values match up to labels and fix if
not correct
Time_Diff = ActiveCell.Offset(60 * (i - 1) + 60 -
CellsShifted, -23).Value - ActiveCell.Offset(60 * (i - 1) + 1 - CellsShifted,
-23).Value
If Not Time_Diff < 60.9 Then '<60.9 because some values
recorded are not exactly 1 second
CellsShifted = CellsShifted + Fix_Time(i)
Else
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Perform calcs on four modes and place in separate table '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Time at end of Mode 4
Range("Y" & i + 9).Value = ActiveCell.Offset(0,
-23).Range("A" & 60 * (i - 1) + 60 - CellsShifted)
'Control Oxygen for Modes 3 and 4 - 5 sec after start of
Mode 3
Range("Z" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -20).Range("A" & 60 * (i - 1) + 47 + 5 - CellsShifted &
":A" & 60 * (i - 1) + 60 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'Front UEGO averaged for Mode 2 and 3 - 3 sec after start of
Mode 2
Range("AA" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -8).Range("A" & 60 * (i - 1) + 41 + 3 - CellsShifted &
":A" & 60 * (i - 1) + 56 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'Inlet Temp is average temperature at mode 1 - 10 last
seconds averaged
Range("AB" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -11).Range("A" & 60 * (i - 1) + 1 + 30 - CellsShifted &
":A" & 60 * (i - 1) + 40 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'Average Bed T for Mode 1 - 10 last seconds
Range("AC" & i + 9).FormulaR1C1 = "=Average(" &
ActiveCell.Offset(0, -10).Range("A" & 60 * (i - 1) + 1 + 30 - CellsShifted &
":A" & 60 * (i - 1) + 40 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'T Max Bed T for all modes
Range("AD" & i + 9).FormulaR1C1 = "=Max(" &
ActiveCell.Offset(0, -10).Range("A" & 60 * (i - 1) + 1 - CellsShifted & ":A"
& 60 * (i - 1) + 60 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'R UEGO peak during Modes 2 and 3
Range("AE" & i + 9).FormulaR1C1 = "=Max(" &
ActiveCell.Offset(0, -6).Range("A" & 60 * (i - 1) + 41 - CellsShifted & ":A"
& 60 * (i - 1) + 56 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
'R UEGO peak during Modes 4 and the next cycle's 1
Range("AF" & i + 9).FormulaR1C1 = "=Max(" &
ActiveCell.Offset(0, -6).Range("A" & 60 * (i - 1) + 57 - CellsShifted & ":A"
& 60 * (i - 1) + 60 + 40 - CellsShifted).Address(ReferenceStyle:=xlR1C1) & ")"
End If
Next
Label_Av = CellsShifted
End Function