Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default vba custom function sum highest consecutive numbers in range excel

I am trying to write a custom function HICON which takes 2 arguments :the
range to be used and the number of consecutive cells to be used . The idea is
that if for example the range was A1:A100 and the number was 5 the formula
would evaluate the sum of A1:A5 then A2:A6 and so on until it got to A94:A100
then it would use whichever of these sums gave the highest total as the
result of the function.
Can anyone suggest the VBA code to use in EXCEL 2003 for this function
please.
Email for replies is
Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default vba custom function sum highest consecutive numbers in range excel

Hi

Try this:

Dim MyArray()
Dim TargetRange As Range

Function HICON(Target As Range, Evaluate As Integer) As Double
Size = Target.Rows.Count / Evaluate
ReDim MyArray(1 To Size)
Pointer = 1
For c = 1 To Size
Set TargetRange = Range(Target.Cells(Pointer, 1), Target.Cells(Pointer +
Evaluate - 1, 1))
MyArray(c) = Application.WorksheetFunction.Sum(TargetRange)
Debug.Print MyArray(c)
Pointer = Pointer + Evaluate
Next
For c = 1 To UBound(MyArray)
If MyArray(c) t Then t = MyArray(c)
Next
HICON = t
End Function

Best regards,
Per

"trimline" skrev i meddelelsen
...
I am trying to write a custom function HICON which takes 2 arguments :the
range to be used and the number of consecutive cells to be used . The idea
is
that if for example the range was A1:A100 and the number was 5 the formula
would evaluate the sum of A1:A5 then A2:A6 and so on until it got to
A94:A100
then it would use whichever of these sums gave the highest total as the
result of the function.
Can anyone suggest the VBA code to use in EXCEL 2003 for this function
please.
Email for replies is
Thank you


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highest total of any three consecutive numbers in a range. [email protected] Excel Worksheet Functions 13 April 3rd 23 07:01 PM
how do i highlight the ten highest numbers in a range? Help Wanted Excel Discussion (Misc queries) 3 May 5th 09 06:39 PM
Highest 3 in 10 Consecutive Numbers Dan Excel Worksheet Functions 17 March 28th 08 06:24 AM
Highest 5 numbers in a range turn red mjones Excel Discussion (Misc queries) 4 September 13th 07 10:02 PM
How do I add only the highest three numbers in a range of data? emac_mommy Excel Worksheet Functions 4 January 9th 05 09:40 AM


All times are GMT +1. The time now is 06:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"