joel;580656 said:
I made some changes to the code below. I don't know where you want t
put the average of all the totals. I also don't know what the last se
of values should be.
From your last instructions you said you ran the macro on differen
data streams. I think you want to keep a worse case of the differen
data streams but not sure. You could also means that the min and ma
are refering to a single data stream.
The evaluate method refers to the worksheet function names the AV
should be Average.
Sub GetHigh()
Const GroupSize = 13
LastRow = Range("AB" & Rows.Count).End(xlUp).Row
MaxCount = 0
FirstRow = 0
LowestAverage = 0
HighestAverage = 0
TotalSum = 0
NumberofSums = 1
'find the hisghest consecuitive 13 numbers by getting the sum of th
values
For RowCount = 2 To (LastRow - GroupSize + 1)
Total = Evaluate("Sum(AB" & RowCount & ":AB" & (RowCount + GroupSiz
- 1) & ")")
If Total > MaxCount Then
FirstRow = RowCount
MaxCount = Total
End If
TotalSum = TotalSum + Total
NumberofSums = NumberofSums + 1
Average = Evaluate("Average(AB" & RowCount & ":AB" & (RowCount
GroupSize - 1) & ")")
If LowestAverage = 0 Then
LowestAverage = Average
Else
If Average < LowestAverage Then
LowestAverage = Average
End If
If Average > HighestAverage Then
HighestAverage = Average
End If
End If
Next RowCount
Set FivePreviousRows = Range("AB" & (FirstRow - 5) & ":AB" & (FirstRo
- 1))
Range("W2") = FivePreviousRows.Address
Set DataRange = Range("AB" & FirstRow & ":AB" & (FirstRow + GroupSize
1))
Min = WorksheetFunction.Min(DataRange)
Range("W3") = Min
Range("W4") = DataRange.Address
StartRow = FirstRow + GroupSize
EndRow = StartRow + 21
'Don't exceed the length of data
If EndRow > LastRow Then
EndRow = LastRow
End If
Set TwentyTwoNextRows = Range("AB" & StartRow & ":AB" & (EndRow))
Range("W5") = TwentyTwoNextRows.Address
'copy data
Range("AB" & (FirstRow - 5) & ":AB" & EndRow).Copy _
Destination:=Range("F4")
Range("T8") = LowestAverage
Range("T9") = HighestAverage
'where does this go?
TotalAverage = TotalSum / NumberofSums
End Sub
Joel,
You stated;
I made some changes to the code below. I don't know where you want to
put the average of all the totals. I also don't know what the las
set
of values should be.
For a bit more clarity I will briefly say this, that the total 40 cell
of values that I used in my previous example represent a pressure curv
of 40 data points per second and when displayed in a line chart, revea
a pressure rise (the first 5 data points, a peak (the 13 highest dat
points), a decay (of 3 data points, and finally a low between eac
pressure curve (of 19 data points), hence the decay and low value
comprised the 22 consecutive values that followed the targeted 13 hig
values. I hope I haven’t muddy the water, but I’ll bet that you get th
picture a little clearer now.
So, in answer to your question of > “where to put the average of all the totals?” the search results value would be save into the cell location a
follows;
The cells to store the addresses of the second macro for the averag
high consecutive values;
Preceding 5 cell Group Range Address in T7
Lowest 1 of the Average Highest 13 Value in T8
Average Highest 13 group Range Address in T9
Trailing 22 Cell Group Range Address in T10
And the range to copy the full consecutive 40 cell values into i
"AK2:AK41".
In answer to your next question of > “I also don't know what the last set
That is understandable, because I worded that part of my message to yo
pretty poorly; as I was think aloud to myself when I wrote it. Pleas
excuse!
Just understand that when the data stream is generated, the targeted 1
high values appear to always be generated earlier in the column data an
then begins to plateau down to a lower set of high values. This is why I
need an average set of high values to compare. So please disregard my
remark about seeking the last set, seeking the average of high values is
a far better approach to achieving my goal during the corrective action
calculations that are ready and waiting for these search results.
You Asked;
From your last instructions you said you ran the macro on different
data streams. I think you want to keep a worse case of the different
data streams but not sure. You could also means that the min and max
are refering to a single data stream.
Yes, I loaded previously saved data streams one at a time into the same
source data column beginning at ”AB2” to examine the performance of the
macro search results. When the worst case is determined, another macro
attached to a button on the worksheet is run to save that data to a
different location to calculate corrective actions. So yes, in that
respect the reference is always to a single data stream intended for the
search task of both macros. Note, that the search result from each macro
will be saved to separate locations as described. In addition, both
macros must remain as separate utilities.
The main purpose of having a second macro to locate the average 13 high
values is to better establish a low end boundary in comparison to the
previous maximum 13 high values during the corrective action
calculation, but the first macro may not be needed in every examination.
My thinking is that the second macro we're working on can target the
average 13 high values group, relative to all of the groups of high/peak
values and capture that set of 40 values. The completion of this second
macro will finally resolve this problem I’ve been working on for months.
:
I am attaching a text file to this message of an actual data stream you
can use to help in testing your macro.
So thank you again Joel for sticking with me on this!
Cecil,
+-------------------------------------------------------------------+
|Filename: DataStream.txt |
|Download:
http://www.thecodecage.com/forumz/attachment.php?attachmentid=382|
+-------------------------------------------------------------------+