View Single Post
  #19   Report Post  
Posted to microsoft.public.excel.programming
L. Howard L. Howard is offline
external usenet poster
 
Posts: 852
Default How to increment the k in LARGE(array,k)

On Saturday, May 30, 2015 at 1:38:28 PM UTC-7, Claus Busch wrote:
Hi Howard,

Am Sat, 30 May 2015 13:28:09 -0700 (PDT) schrieb L. Howard:

Sort of hard to explain the concept. Thanks for your patience too.


it is also for me esier when I see the data.
Do you use the latest version with the array? It is a bit faster.


Regards
Claus B.


Hi Claus,

This code from "Large Rev3" is what I'm using.

Sure seems fine to me.

Howard


Sub Test()
Dim i As Long, j As Long, LCol As Long
Dim varOut() As Variant
Dim valL As Long, valH

LCol = Application.CountA(Sheets("Sheet1").Range("K2:KN2" ))

With Sheets("Sheet2")
ReDim Preserve varOut(LCol - 1, 1)
varOut(0, 1) = Evaluate("=Max(Sheet1!K2:KN2)")
varOut(0, 0) = Evaluate("=INDEX(Sheet1!$K$1:$KN$1,MATCH(Max(Sheet 1!K2:KN2),Sheet1!K2:KN2,0))")

For i = 1 To LCol - 1
For j = 1 To LCol + 1
valL = Evaluate("=LARGE(Sheet1!K" & i + 2 & ":KN" & i + 2 & "," & j & ")")
valH = Evaluate("=INDEX(Sheet1!$K$1:$KN$1,Match(" & valL & ",Sheet1!K" & i + 2 & ":KN" & i + 2 & ",0))")
If valH < varOut(i - 1, 0) Then
varOut(i, 0) = valH
varOut(i, 1) = valL
Exit For
End If
Next j
Next i
.Range("A2").Resize(LCol, 2) = varOut
End With
End Sub