Skip,
Since your code is difficult to understand, I have to stick with Zathras's code.
I played with Zathras's code but could not figure out how to add Series chart (in column E and F for each block)
Could you, Zathras or anyone can help me?
Thanks a bunch.
Here's the latest code:
Option Explicit
Const PRESSURE_DATA_COLUMN = "B:B"
Const HIGH_PRESSURE = 11300
Const HP_SYMBOL = "HP"
Const START_SYMBOL = """START"""
Const END_SYMBOL = """END"""
Const TICK_INTERVAL = 3 '(seconds)
Const SECONDS_PER_DAY = 86400
Sub FindBlocks()
Dim c As Range
Dim nStartValue As Double
Dim nStartAddress As String
Dim iSeconds As Integer
Dim iTime As Double
Application.ScreenUpdating = False
nStartValue = 0
For Each c In Intersect(ActiveSheet.UsedRange, Range(PRESSURE_DATA_COLUMN))
If c.Value > 0 Then
' Set clock start for the whole worksheet 0:00:00 with increment is 3
iTime = iSeconds / SECONDS_PER_DAY
c.Offset(0, 7) = WorksheetFunction.Text(iTime, "h:mm:ss"
iSeconds = iSeconds + TICK_INTERVAL
End If
If c.Value > HIGH_PRESSURE Then
' Mark "HP"
c.Offset(0, 1) = HP_SYMBOL
If c > nStartValue Then
nStartValue = c
nStartAddress = c.Offset(0, 2).Address
End If
Else
' Clear "HP" and set "Start" (with time ticks)
c.Offset(0, 1) = ""
StartTimeTicks nStartAddress
nStartValue = 0
End If
' Clear "Start"
c.Offset(0, 2) = ""
Next c
' Set "Start" (with time ticks)
StartTimeTicks nStartAddress
Application.ScreenUpdating = True
End Sub
Private Sub StartTimeTicks(StartAddress As String)
Dim rng As Range
Dim nSeconds As Integer
Dim nTime As Double
Dim pBase As Double
Dim tbase As Double
If StartAddress <> "" Then
Set rng = Range(StartAddress)
pBase = rng.Offset(0, -2).Value
tbase = rng.Offset(0, -3).Value
rng.Value = START_SYMBOL
While rng.Offset(0, -1) = HP_SYMBOL
nTime = nSeconds / SECONDS_PER_DAY
rng.Offset(0, 1) = WorksheetFunction.Text(nTime, "h:mm:ss"
rng.Offset(0, 2) = pBase - rng.Offset(0, -2).Value ' Calculate Diff. P
rng.Offset(0, 3) = tbase - rng.Offset(0, -3).Value ' Calculate Diff. T
Set rng = rng.Offset(1, 0)
nSeconds = nSeconds + TICK_INTERVAL
Wend
If rng.Offset(-1, 0) <> START_SYMBOL Then
rng.Offset(-1, 0) = END_SYMBOL
Else
rng.Offset(-1, 0) = START_SYMBOL & " (" & END_SYMBOL & "
"
End If
Set rng = Nothing
End If
End Sub
P.S. I have to repeat this question with this subject. Sorry
Since your code is difficult to understand, I have to stick with Zathras's code.
I played with Zathras's code but could not figure out how to add Series chart (in column E and F for each block)
Could you, Zathras or anyone can help me?
Thanks a bunch.
Here's the latest code:
Option Explicit
Const PRESSURE_DATA_COLUMN = "B:B"
Const HIGH_PRESSURE = 11300
Const HP_SYMBOL = "HP"
Const START_SYMBOL = """START"""
Const END_SYMBOL = """END"""
Const TICK_INTERVAL = 3 '(seconds)
Const SECONDS_PER_DAY = 86400
Sub FindBlocks()
Dim c As Range
Dim nStartValue As Double
Dim nStartAddress As String
Dim iSeconds As Integer
Dim iTime As Double
Application.ScreenUpdating = False
nStartValue = 0
For Each c In Intersect(ActiveSheet.UsedRange, Range(PRESSURE_DATA_COLUMN))
If c.Value > 0 Then
' Set clock start for the whole worksheet 0:00:00 with increment is 3
iTime = iSeconds / SECONDS_PER_DAY
c.Offset(0, 7) = WorksheetFunction.Text(iTime, "h:mm:ss"
iSeconds = iSeconds + TICK_INTERVAL
End If
If c.Value > HIGH_PRESSURE Then
' Mark "HP"
c.Offset(0, 1) = HP_SYMBOL
If c > nStartValue Then
nStartValue = c
nStartAddress = c.Offset(0, 2).Address
End If
Else
' Clear "HP" and set "Start" (with time ticks)
c.Offset(0, 1) = ""
StartTimeTicks nStartAddress
nStartValue = 0
End If
' Clear "Start"
c.Offset(0, 2) = ""
Next c
' Set "Start" (with time ticks)
StartTimeTicks nStartAddress
Application.ScreenUpdating = True
End Sub
Private Sub StartTimeTicks(StartAddress As String)
Dim rng As Range
Dim nSeconds As Integer
Dim nTime As Double
Dim pBase As Double
Dim tbase As Double
If StartAddress <> "" Then
Set rng = Range(StartAddress)
pBase = rng.Offset(0, -2).Value
tbase = rng.Offset(0, -3).Value
rng.Value = START_SYMBOL
While rng.Offset(0, -1) = HP_SYMBOL
nTime = nSeconds / SECONDS_PER_DAY
rng.Offset(0, 1) = WorksheetFunction.Text(nTime, "h:mm:ss"
rng.Offset(0, 2) = pBase - rng.Offset(0, -2).Value ' Calculate Diff. P
rng.Offset(0, 3) = tbase - rng.Offset(0, -3).Value ' Calculate Diff. T
Set rng = rng.Offset(1, 0)
nSeconds = nSeconds + TICK_INTERVAL
Wend
If rng.Offset(-1, 0) <> START_SYMBOL Then
rng.Offset(-1, 0) = END_SYMBOL
Else
rng.Offset(-1, 0) = START_SYMBOL & " (" & END_SYMBOL & "
End If
Set rng = Nothing
End If
End Sub
P.S. I have to repeat this question with this subject. Sorry