Hi, I've created an UDF which takes some arguments and returns a list as a result, see example:
Now, I'm refering to that function in subroutine where I'm asigning a variable to a one of the list members, say:
which gives me a expected result of 10.488, i. e. Sqr(5^2 + 6^2 + 7^2).
How could I use my function in a sheet and get same result, depending which member of a list I want?
If I enter formula "=myFunction(5, 6, 7)(3)" in a cell, I get #REF! error, but when I enter it as "=myFunction(5, 6, 7)" I get spilled result with all list members in adjacent cells. So, I just want to get, say, 3rd member of a list. How to do that?
VBA Code:
Function myFunction(a, b, c)
Dim MyFunction_result(1 To 4) As Double
result1 = a + b + c
result2 = a * b * c
result3 = Sqr(a ^ 2 + b ^ 2 + c ^ 2)
result4 = a * (b + c)
MyFunction_result(1) = result1
MyFunction_result(2) = result2
MyFunction_result(3) = result3
MyFunction_result(4) = result4
MyFunction = myFunction_result
End Function
Now, I'm refering to that function in subroutine where I'm asigning a variable to a one of the list members, say:
VBA Code:
Sub testMyFunction()
variable = myFunction(5, 6, 7)(3)
End Sub
which gives me a expected result of 10.488, i. e. Sqr(5^2 + 6^2 + 7^2).
How could I use my function in a sheet and get same result, depending which member of a list I want?
If I enter formula "=myFunction(5, 6, 7)(3)" in a cell, I get #REF! error, but when I enter it as "=myFunction(5, 6, 7)" I get spilled result with all list members in adjacent cells. So, I just want to get, say, 3rd member of a list. How to do that?