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..
Bookmarks