简体   繁体   English

数组公式结果连接到单个单元格中

[英]Array formula result concatenated into single cell

Is it possible to take the return values from an array formula and concatenate them into a single cell?是否可以从数组公式中获取返回值并将它们连接到一个单元格中? For example, I have a simple spreadsheet with rows for project tasks which looks like this:例如,我有一个简单的电子表格,其中包含项目任务的行,如下所示:

Task #    Description    Blocked on    Blocking
-----------------------------------------------
1         Task 1         2             
2         Task 2                       $formula
3         Task 3         2             

I would like the formula in cell D3 to return "1, 3" (it would also be great to put multiple values in the Blocked On cell).我希望单元格 D3 中的公式返回“1, 3”(将多个值放入 Blocked On 单元格中也很好)。 I've currently got it returning "1" with the following formula:我目前已经使用以下公式返回“1”:

=(INDEX($A2:$A999,MATCH(A3,$C2:$C999,0)))

the formula you are looking for is (in d3): =IF($C$2:$C$999=$A4;$A$2:$A$999;"") +ctrl+shift+enter您要查找的公式是(在 d3 中):=IF($C$2:$C$999=$A4;$A$2:$A$999;"") +ctrl+shift+enter

make sure you enter it as an array确保将其作为数组输入

(NOTE: you may also need to change ; to , depending on your regional settings) (注意:您可能还需要将;更改为具体取决于您的区域设置)

This will return content of A if data in C matched current Ai.如果 C 中的数据与当前 Ai 匹配,这将返回 A 的内容。 You can see only one result now, since the result is array, but if you use Transpose() and select multiple cells in same row, then with F2 then ctrl+shift+enter you will see all results in a row: Ex: select D3,K3, press F2: write formula: =Transpose(IF($C$2;$C$999=$A4:$A$2;$A$999,"")).您现在只能看到一个结果,因为结果是数组,但是如果您使用 Transpose() 并选择同一行中的多个单元格,然后使用 F2 然后按 ctrl+shift+enter 您将看到一行中的所有结果:例如:选择D3,K3,按F2:写公式:=Transpose(IF($C$2;$C$999=$A4:$A$2;$A$999,""))。 press ctrl+shift+enter..: (again you may need to write: =Transpose(IF($C$2,$C$999=$A4:$A$2,$A$999.""))...)按 ctrl+shift+enter..:(你可能需要再次写:=Transpose(IF($C$2,$C$999=$A4:$A$2,$A$999.""))...)

but you must have many columns to the right since empty results still occupy columns, Even if empty strings are handled to occupy no columns.但是你必须在右边有很多列,因为空结果仍然占据列,即使空字符串被处理为不占据任何列。 there still remains the matter of unknown results-columns.仍然存在未知结果列的问题。 So I propose usage of a VBA function (one I wrote quite a while ago) to Concatenate valid results in one cell (with any delimiter you like).因此,我建议使用 VBA 函数(我很久以前写的一个函数)在一个单元格中连接有效结果(使用您喜欢的任何分隔符)。

Final proposed formula in D3: =MyConCat("-";IF($C$2:$C$999=$A2;$A$2:$A$999;"")) +ctrl+shift+enter D3 中最终提出的公式: =MyConCat("-";IF($C$2:$C$999=$A2;$A$2:$A$999;"")) +ctrl+shift+enter

and code for MyConCat (to place in a module in VBA code area):和 MyConCat 的代码(放置在 VBA 代码区域的模块中):

' MyConCat
'
' Very simple By Apostolos Goulandris
Function MyConCat(myDelimiter As String, Avar) As String
    Dim b As Variant, Dum As String
    If IsMissing(myDelimiter) Then myDelimiter = ""
    For Each b In Avar
        Dum = IIf(Len(b) > 0, Dum & myDelimiter & b, Dum)
    Next
    MyConCat = IIf(Len(myDelimiter) > 0, Mid(Dum, Len(myDelimiter) + 1, Len(Dum)), Dum)
End Function

Try this in Cells D3.在单元格 D3 中试试这个。 Enter as Array formula Ctrl + Shift + Enter.输入数组公式 Ctrl + Shift + Enter。

=IFERROR(LEFT(SUBSTITUTE(CONCAT(IF(A3=C2:C4,A2:A4)&"-"),"FALSE-",""),LEN(SUBSTITUTE(CONCAT(IF(A3=C2:C4,A2:A4)&"-"),"FALSE-",""))-1),"")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM