I am trying to create a function in excel via VBA and wondering if excel inbuilt function can be used within that function. for example, functions like Lookup or Match.I have the solution with VBA & formula but interested to know if function can do the same.
I am trying to create a function where VLookup should only return value for first found item.
'function which can return the Vlookup value only for 1st found value
Function SLOOKUP(Pvalue As Range, Rng As Range, Rng1 As Range, pIndex As Long)
Dim Cvalue As Variant
Dim Mvalue As Long
Dim Uvalue As Long
Dim Result As Variant
Result = ""
Cvalue = Pvalue.Value
Mvalue = Application.Worksheet.Function.Match(Cvalue, Rng, -1)
Uvalue = Pvalue.Row
If Mvalue = Uvalue Then
Result = Application.Worksheet.Function.VLookup(Cvalue, Rng1, pIndex, 0)
Else
Result = 0
End If
SLOOKUP = Result
End Function