如何在Excel中获取单个单元格中学生状态为合格或不合格的数字列表

How to Get List Of Numbers Whose Students Status is Pass or Failed in Single Cell in Excel

我想得到一个公式,它以逗号分隔的列表给出输出,其学生状态在 Excel 中的单个单元格中为通过或未通过。

谢谢

试试这个没有 Textjoin 函数和辅助列的公式解决方案

E2中输入数组公式(按Ctrl+Shift+Enter确认)并向下复制:

=MID(SUBSTITUTE(TEXT(SUM(SMALL((IF($B:$B=D2,TEXT($A:$A,"00"),"")=TEXT(ROW(:),"00"))*ROW(:),ROW(:))*100^(10-ROW(:))),REPT(" 00",10))," 00",""),2,99)

并且,

如果您想要使用逗号分隔符的结果值,则数组公式变为:

=MID(SUBSTITUTE(TEXT(SUM(SMALL((IF($B:$B=D2,TEXT($A:$A,"00"),"")=TEXT(ROW(:),"00"))*ROW(:),ROW(:))*100^(10-ROW(:))),REPT("\,00",10)),",00",""),2,99)

以下解决方案使用 UDF。首先将以下自定义函数放在常规模块中(Visual Basic 编辑器 >> 插入 >> 模块)...

Function AConcat(a As Variant, Optional Sep As String = "") As String
' Harlan Grove, Mar 2002

    Dim Y As Variant

    If TypeOf a Is Range Then
        For Each Y In a.Cells
            AConcat = AConcat & Y.Value & Sep
        Next Y
    ElseIf IsArray(a) Then
        For Each Y In a
            AConcat = AConcat & Y & Sep
        Next Y
    Else
        AConcat = AConcat & a & Sep
    End If

    AConcat = Left(AConcat, Len(AConcat) - Len(Sep))

End Function

然后试试下面的工作表数组公式,需要用CONTROL+SHIFT+ENTER确认...

=SUBSTITUTE(AConcat(IF($B:$B="Pass",","&$A:$A,"")),",","",1)

=SUBSTITUTE(AConcat(IF($B:$B="Fail",","&$A:$A,"")),",","",1)