[英]Use comma separated value of a single cell as input for array formula
I want to built an array formula that accepts separated values of a single cell as input:我想构建一个接受单个单元格的分隔值作为输入的数组公式:
Cell A1: 1;3;4单元格 A1:1;3;4
Cell A2: ={Sum(If(A3:F3)=A1,A4:F4))}单元格 A2:={Sum(If(A3:F3)=A1,A4:F4))}
How can I tell excel to intepret the string in A1 as array?如何告诉 excel 将 A1 中的字符串解释为数组? I tried to set up a custom vba function, but I was not able to return the vba array correctly to the excel formula.
我尝试设置自定义 vba 函数,但无法将 vba 数组正确返回到 excel 公式。
Can anyone help?任何人都可以帮忙吗?
What I tried with VBA:我用 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).在上面的公式中,我用 Matrix(A1) 替换了 A1。 But the values of the vectors are returned as strings instead of integers (sorry, actually using a german Excel):
但是向量的值作为字符串而不是整数返回(抱歉,实际上使用的是德国 Excel):
Thanks Peter谢谢彼得
Some clever so-and-so will provide you with a formula I expect, but here is a VBA solution.一些聪明的某某将为您提供我期望的公式,但这里有一个 VBA 解决方案。 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 C1中的公式是
=matrix(A1,A3:D4)
Note that Split
returns an array.请注意,
Split
返回一个数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.