Results 1 to 28 of 28

NthMatch UDF as An Alternative to Array function...

Threaded View

  1. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Thumbs up Re: NthMatch UDF as An Alternative to Array function...

    Improved A bit..

    Now It jump over the result when Match No. matches the row no....
    means It stops looping when Nth Match is found.. and throws the result...

    Here is the code..

    Function NthMatch(ByVal Lvalue As Variant, ByVal Lrange As Variant, Mnum As Variant) As Integer
    '*************Developed by Vikas Gautam ****************
    '*************www.Excel-buzz.blogspot.com***************
    Dim Arr()
    ReDim Arr(0)
    r = 0
    If IsArray(Lrange) Then
        For Each cell In Lrange
            c = c + 1 'c counts row no. to be checked
            If cell = Lvalue Then
                ReDim Preserve Arr(r)
                Arr(r) = c 'assigning row no. of the match row to the Arr
                If r = Mnum - 1 Then NthMatch = Arr(Mnum - 1): Exit Function 'Stops looping when Nth Match is found..
                r = r + 1
            End If
        Next
    Else
        If Lvalue = Lrange Then Arr(0) = 1 'if the Lrange is a single value ....
    End If
    NthMatch = Arr(Mnum - 1)
    End Function
    If there are chances of improvement then don't hesitate.. Have a comment..
    Attached Files Attached Files
    Last edited by Vikas_Gautam; 08-09-2014 at 10:38 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Alternative to using an array formula for {=LARGE(IF(... function
    By Rabiah in forum Excel Formulas & Functions
    Replies: 28
    Last Post: 05-30-2014, 05:52 AM
  2. UDF Lookup function as an alternative to array functions & match/index
    By Andrew_Harris in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2012, 09:34 PM
  3. [SOLVED] Non array alternative for percentile function
    By vandan_tanna in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-22-2012, 11:43 AM
  4. Alternative to an array formula.
    By RunHard in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-16-2009, 09:18 AM
  5. Array Formula Alternative
    By smninos in forum Excel General
    Replies: 10
    Last Post: 07-15-2009, 04:31 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1