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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rank & Average 1

Status
Not open for further replies.

VincentCrimmins

Programmer
Jan 16, 2008
37
IE
Hi,

I'm trying to create a function that will take in 10 values and will return the average of the 3 largest values.

Any ideas? I'm struggling badly!

Thanks,
 
Hi,

How are you struggling? Please be specific.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Sorry, that should say I'm trying to create the function in VBA for Excel.

Thanks...
 


What do you have so far?

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
So far I can calculate the max value and the average of all the values, but I want to get the average of the top three:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

For HighArrayData = 0 To 9
HighSeg = Range("C" & HighRow - SegmentSize + 1 & ":C" & HighRow)
HighSeg1 = Range("C" & HighRow - SegmentSize * 2 + 1 & ":C" & HighRow - SegmentSize)
HighDiff = (Excel.WorksheetFunction.Max(HighSeg) / Excel.WorksheetFunction.Max(HighSeg1)) - 1
varHighData(HighArrayData) = HighDiff
HighRow = HighRow - SegmentSize
If HighArrayData = SegmentNumber - 2 Then
PeakHigh = Excel.WorksheetFunction.Max(HighSeg1)
End If
Next

HighArrayMax = Excel.WorksheetFunction.Max(varHighData)
HighArrayAvg = Excel.WorksheetFunction.Average(varHighData)


<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 



Why use VB?

Use RANK and AVERAGE.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The values are sorted by 'date', so I can't sort them by 'value' and then get the average of the top three.
 


Who said anything about SORTING?

I am referring to the RANK & AVERAGE spreadsheet functions.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Sorry, I don't understand. The data is as follows:

A B C
Date Value Average(Top 3 of the Last 10 Values)
23-Jan-09 16.93
22-Jan-09 16.89
21-Jan-09 17.13
20-Jan-09 16.98
19-Jan-09 16.88
16-Jan-09 17.11
15-Jan-09 17.17
14-Jan-09 17.13
13-Jan-09 17.00
12-Jan-09 16.98
09-Jan-09 16.98
08-Jan-09 16.89
07-Jan-09 16.94
06-Jan-09 16.94
05-Jan-09 16.87
02-Jan-09 16.95
01-Jan-09 16.95
 


Sorry, I meant to refer your to the LARGE function, rather than the RANK function.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
That's perfect!

Thanks for that Skip, I never came across the LARGE function before.

Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top