Index Match in VBA function

SonnyB25

New Member
Joined
Jun 19, 2018
Messages
3
Hi,

I'm trying to develop a Index/Match function in VBA with multiple criteria (using the "&" as in an excel function) - but it doesn't work.

Does anybody know what I'm doing wrong?



Function prove(X As Range, Y As Range, Z As Range)


A = Application.WorksheetFunction.Index(X, Application.WorksheetFunction.Match("Pre-SS" & "PS", Y & Z, 0), 1)


prove = A


End Function

Thanks in advance!
Sonny
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Does this do what you want?

Code:
Dim arr, arr1, arr2, i As Long, myVal As Variant

arr = X: arr1 = Y: arr2 = Z

For i = LBound(arr1, 1) To UBound(arr1, 1)
    If LCase(arr1(i, 1)) = "pre-ss" Then
        If LCase(arr2(i, 1)) = "ps" Then
            myVal = arr(i, 1)
            Exit For
        End If
    End If
Next
       
If Not IsEmpty(myVal) Then
    prove = myVal
Else
    prove = CVErr(xlErrNA)
End If
 
Upvote 0
Not quite. I need it to be a function based on the "application.worksheetfunction.xxx".

The function works in excel (within VBA), I just want to replicate it to a VBA function.
 
Upvote 0
Sonny

You can't use something like Y & Z to combine 2 ranges in VBA.
 
Upvote 0
Maybe something like this...

Code:
Function prove(X As Range, Y As Range, Z As Range)
    Dim A As Variant
    
    A = Evaluate("=INDEX(" & X.Address & ", Match(""Pre-SS""&""PS""," & Y.Address & "&" & Z.Address & ", 0))")
    prove = A
End Function

M.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,206
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top