Results 1 to 5 of 5

Thread: Nth Largest Unique Value in an Array (UDF)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    Quote Originally Posted by Admin View Post
    Here is an UDF to find the nth Largest unique value from an array.

    Function NTHLARGESTUNIQUE(ByRef InpData, Optional ByVal Nth As Long = 1)

    Dim i As Long, UB1 As Long, UB2 As Long

    NTHLARGESTUNIQUE = CVErr(xlErrNum)
    If TypeOf InpData Is Range Then
    If InpData.Rows.Count > 1 And InpData.Columns.Count = 1 Then
    InpData = Application.Transpose(InpData.Value2)
    ElseIf InpData.Rows.Count = 1 And InpData.Columns.Count > 1 Then
    InpData = Application.Transpose(Application.Transpose(InpDat a.Value2))
    Else
    Exit Function
    End If
    End If
    ....
    .... < snip >
    ....
    Just wanted to point out that the double call to Application.Transpose (highlighted in bold) can be replaced with a single call to Application.Index (which should also be faster)...

    InpData = Application.Index(InpData.Value2, 1, 0)


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 06-10-2023 at 01:38 PM.

Similar Threads

  1. Nth Such-And-Such Day Of The Month
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 6
    Last Post: 01-02-2020, 06:48 PM
  2. Fetch Nth last item from a list
    By SDruley in forum Excel Help
    Replies: 2
    Last Post: 01-01-2013, 09:28 AM
  3. Nth Working Day Including Saturday
    By Excel Fox in forum Download Center
    Replies: 0
    Last Post: 10-10-2012, 02:41 AM
  4. Replies: 2
    Last Post: 01-07-2012, 12:11 AM
  5. Average Of The X Largest Numbers
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-16-2011, 04:15 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •