I created a function called test
Function test(a() As Variant)
Debug.Print "Type: "; TypeName(a)
Debug.Print "lb: "; LBound(a)
Debug.Print "ub: "; UBound(a)
test = a(UBound(a))
End Function
It is okay when I type
=test({4,5,6,8,9})
in a cell. It returns 9.
Let's have some data on the worksheet.
A B
1 1 3
2 0 6
3 1 9
4 0 7
5 1 8
I type the below formula with ctrl+shift+enter in a cell.
{=test(IF(A1:A5=1,B1:B5))}
I think an array is passed into test but it doesn't work. It can return LBound(a) and UBound(a) as usual but test = a(UBound(a)) fails.
What is the problem? How can I write a write VBA user defined function to take array argument from IF.
=test{(IF(A1:A5=1,B1:B5))}Try this