数据透视表字符串逗号分隔

时间:2011-06-08 10:22:37

标签: excel-2007 pivot

我有一个数据源,我需要在一个夏季表中显示它们。

请参阅atached文件的输出表,让我知道如何制作

Please find the sample attachment

1 个答案:

答案 0 :(得分:0)

一种方法是使用用户定义的函数来制作以逗号分隔的列表

Function MergeCOO(rId As Range, r1 As Range, r2 As Range) As String
    Dim vIdx As Variant
    Dim vCOO As Variant
    Dim Id As Variant
    Dim i As Long, str As String
    Dim c As New Collection

    Id = rId.Value
    vIdx = r1
    vCOO = r2

    On Error Resume Next
    For i = LBound(vIdx, 1) To UBound(vIdx, 1)
        If vIdx(i, 1) = Id Then
            c.Add vCOO(i, 1), vCOO(i, 1)
            If Err.Number <> 0 Then Err.Clear
        End If
    Next

    For i = 0 To c.Count
        str = str & c.Item(i) & ","
    Next

    MergeCOO = Left(str, Len(str) - 1)

End Function

将工作表添加到工作表

中的列L
=MergeCOO([@[HS Code]],[HS Code],[COO])

然后,您可以根据需要将此额外列添加到报告中