简体   繁体   English

使用单个单元格的逗号分隔值作为数组公式的输入

[英]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.

相关问题 如何在单元格中使用逗号分隔的值作为公式中的参数(特别是数据透视表)? - How to use comma separated values in a cell, as parameters in formula (PivotTable specifically)? 如何从 excel 中的单个单元格计算逗号分隔的特定值 - How to count comma separated specific value from a single cell in excel 在单单元格Excel数组公式中使用IF公式的结果 - Use result of IF formula in single cell Excel array formula 在单个单元格中收集逗号分隔的数据 - Collecting comma separated data in a single cell 从单个单元格中提取由逗号分隔的数据 - Extract data separated by a comma from a single cell Excel:除以逗号分隔的单个单元格数字 - Excel: Dividing comma separated single cell numbers 如何将相同的单元格公式值用作相同公式的输入? - How to use same cell formula value as input for the same formula? Excel公式来检查一个单元格中的逗号分隔列表中的项是否存在于另一单元格中的逗号分隔列表中? - Excel formula to check if items from a comma separated list in one cell exist in a comma separated list in another cell? 是否有一个单元格公式可以在 EXCEL 中获得一个以逗号分隔的列表并增加数字 - is there a one cell formula for getting a comma separated list with increasing numbers in EXCEL 将单元格中的值范围转换为逗号分隔列表 - Turn a value range in a cell into a comma separated list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM