【问题标题】:Combining unique cell's values结合唯一单元格的值
【发布时间】:2015-05-05 21:44:51
【问题描述】:

我正在尝试从 A 列中包含重复名称的列表中获取 B 列的组合值。

Sally  Cookies, Apples
Jamie  Pie
Sally  Muffins
Bob    Jam
Bob    Pie

结果如下:

Sally  Cookies, Apples, Muffins
Jamie  Pie 
Bob    Jam, Pie   

我尝试使用 Unique 进行排序,但我只得到了名称的第一个实例

【问题讨论】:

    标签: excel excel-formula filtering unique


    【解决方案1】:

    A 和 B 列中有数据,例如:

    运行这个宏:

    Sub GatherData()
        Dim Na As Long, Nc As Long, v As String
        Range("A:A").Copy Range("C1")
        Range("C:C").RemoveDuplicates Columns:=1, Header:=xlNo
        Na = Cells(Rows.Count, "A").End(xlUp).Row
        Nc = Cells(Rows.Count, "C").End(xlUp).Row
    
        For i = 1 To Nc
            v = Cells(i, "C").Value
            Cells(i, "D").Value = ""
            For j = 1 To Na
                If v = Cells(j, "A").Value Then
                    Cells(i, "D").Value = Cells(i, "D").Value & "," & Cells(j, "B").Value
                End If
            Next j
        Next i
    
        For i = 1 To Nc
            Cells(i, "D").Value = Mid(Cells(i, "D").Value, 2)
        Next i
    End Sub
    

    将产生:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多