I want to built an array formula that accepts separated values of a single cell as input:
Cell A1: 1;3;4
Cell A2: ={Sum(If(A3:F3)=A1,A4:F4))}
How can I tell excel to intepret the string in A1 as array? I tried to set up a custom vba function, but I was not able to return the vba array correctly to the excel formula.
Can anyone help?
What I tried with VBA:
Function Matrix(vector)
Dim arr As Variant
arr = Array(Split(vector, ";"))
Matrix = arr
End Function
In the above formula I replace A1 by Matrix(A1). But the values of the vectors are returned as strings instead of integers (sorry, actually using a german Excel):
Thanks Peter
Some clever so-and-so will provide you with a formula I expect, but here is a VBA solution. You need to pass two arguments (at least) I think - the array and look-up range.
Function Matrix(vector, r As Range) As Variant
Dim arr As Variant, i As Long, v As Variant
arr = Split(vector, ";")
For i = LBound(arr) To UBound(arr)
v = Application.Match(Val(arr(i)), r.Rows(1), 0)
If IsNumeric(v) Then Matrix = Matrix + r(2, v)
Next i
End Function
The formula in C1 is
=matrix(A1,A3:D4)
Note that Split
returns an array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.