CONCATENATE和IF函数问题

时间:2019-02-13 17:36:43

标签: excel if-statement concatenation formula

我试图将一列包含课程信息(带有文本)或仅包含数字0的数据,并将该列中不等于0的值串到另一个选项卡上的仅一个单元格中。

例如:

[*COLUMN A*]
COURSE B8001
COURSE B8002
0
0
COURSE B8003

^我想参加本专栏...
并把它变成这个...

单元格1:COURSE B8001, COURSE B8002, COURSE B8003(全部在同一列下,仅在一个单元格中)

我一直在使用连接,如果功能无效,则卡住了。

感谢任何帮助

1 个答案:

答案 0 :(得分:1)

如果您具有Office 365 Excel,则可以使用以下数组公式:

=TEXTJOIN(",",TRUE,IF(A1:A100<>0,A1:A100,""))

作为数组公式,退出编辑模式时需要使用Ctrl-Shift-Enter而不是Enter进行确认


如果您没有OFFICE 365 Excel,则需要一个帮助列或vba。

Helper,将其放在B1中并拖动数据的长度:

=IF(A1<>0,A1&","&B2,B2)

您的串联语句将出现在B1中

vba,将其放在工作簿所附的模块中:

Function TEXTJOINIFS(rng As Range, delim As String, ParamArray arr() As Variant)
    Dim rngarr As Variant
    rngarr = Intersect(rng, rng.Parent.UsedRange).Value

    Dim condArr() As Boolean
    ReDim condArr(1 To Intersect(rng, rng.Parent.UsedRange).Rows.Count) As Boolean


    Dim i As Long
    For i = LBound(arr) To UBound(arr) Step 2
        Dim colArr() As Variant
        colArr = Intersect(arr(i), arr(i).Parent.UsedRange).Value
        Dim j As Long
        For j = LBound(colArr, 1) To UBound(colArr, 1)

            If Not condArr(j) Then
                Dim charind As Long
                charind = Application.Max(InStr(arr(i + 1), ">"), InStr(arr(i + 1), "<"), InStr(arr(i + 1), "="))
                Dim opprnd As String
                If charind = 0 Then
                    opprnd = "="
                Else
                    opprnd = Left(arr(i + 1), charind)
                End If
                Dim t As String
                t = """" & colArr(j, 1) & """" & opprnd & """" & Mid(arr(i + 1), charind + 1) & """"
                If Not Application.Evaluate(t) Then condArr(j) = True
            End If
        Next j
    Next i

    For i = LBound(rngarr, 1) To UBound(rngarr, 1)
        If Not condArr(i) Then
            TEXTJOINIFS = TEXTJOINIFS & rngarr(i, 1) & delim
        End If
    Next i

    TEXTJOINIFS = Left(TEXTJOINIFS, Len(TEXTJOINIFS) - Len(delim))

End Function

然后将其命名为SUMIFS:

=TEXTJOINIFS(A:A,",",A:A,"<>0")

enter image description here