Excel 重複項公式

Excel 重複項公式

有人可以告訴我創建 C 列中的確切資料所需的公式嗎:

在此輸入影像描述

B 列中的任何重複儲存格都會將 A 列中的 sku 複製到 C 欄中。

希望我已經解釋清楚了!

答案1

如果您沒有 Office 365 Excel,您將需要 UDF。將此程式碼放入附加到工作簿的模組中:

Function TEXTJOIN(delim As String, skipblank As Boolean, arr)
    Dim d As Long
    Dim c As Long
    Dim arr2()
    Dim t As Long, y As Long
    t = -1
    y = -1
    If TypeName(arr) = "Range" Then
        arr2 = arr.Value
    Else
        arr2 = arr
    End If
    On Error Resume Next
    t = UBound(arr2, 2)
    y = UBound(arr2, 1)
    On Error GoTo 0

    If t >= 0 And y >= 0 Then
        For c = LBound(arr2, 1) To UBound(arr2, 1)
            For d = LBound(arr2, 1) To UBound(arr2, 2)
                If arr2(c, d) <> "" Or Not skipblank Then
                    TEXTJOIN = TEXTJOIN & arr2(c, d) & delim
                End If
            Next d
        Next c
    Else
        For c = LBound(arr2) To UBound(arr2)
            If arr2(c) <> "" Or Not skipblank Then
                TEXTJOIN = TEXTJOIN & arr2(c) & delim
            End If
        Next c
    End If
    If TEXTJOIN <> "" Then 
        TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim)) 
    Else
        TEXTJOIN = ""
    End IF
End Function

然後下面的陣列公式將滿足您的要求:

=TEXTJOIN(" | ",TRUE,IF($A$2:$A$11<>A2,IF($B$2:$B$11=B2,$A$2:$A$11,""),""))

作為陣列公式,退出編輯模式時需要使用 Ctrl-Shift-Enter 而不是 Enter 進行確認。如果操作正確,Excel 就會輸入{}公式。


如果您有 Office 365 Excel,只需使用上面的公式作為陣列公式,無需 UDF。

UDF 模仿 TEXTJOIN 的功能。

在此輸入影像描述

相關內容