Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA: How to Add Chart Objects and Series?

Status
Not open for further replies.

xitu

Technical User
Joined
Oct 1, 2003
Messages
55
Location
US
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 <> &quot;&quot; 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, &quot;h:mm:ss&quot;)
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 & &quot; (&quot; & END_SYMBOL & &quot;)&quot;
End If
Set rng = Nothing
End If
End Sub



P.S. I have to repeat this question with this subject. Sorry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top