1

我的工作表有两列:Column AColumn B

Column A有一个名称列表,并Column B有相应的值。

列表 ( Column A) 中的某些项目在 中具有不同值的重复项Column B

我正在尝试做的是删除重复项,Column A并且每个重复项只有一个,并且它们的所有对应值都在一个单元格中。

例子:

Colmn A      Column B                     Column A      Column B
Apple           7                         Apple            7, 1
Orange          2         will be         Orange           2   
Apple           1

我正在使用下面的公式,但它给了我一个#NAME?错误:

=IF(MATCH(A2,A:A,0), contenate(B:B))

有人可以告诉我我做错了什么吗?

4

1 回答 1

0

这个简短的宏会将结果放在DE列中:

Sub Macro1()
    Dim M As Long, N As Long, rc As Long
    Dim i As Long, j As Long, v As String
    rc = Rows.Count

    Columns("A:A").Copy Columns("D:D")
    Range("D:D").RemoveDuplicates Columns:=1, Header:=xlNo
    M = Cells(rc, 1).End(xlUp).Row
    N = Cells(rc, 4).End(xlUp).Row

    For i = 1 To N
        v = Cells(i, 4)
        For j = 1 To M
            If Cells(j, 1) = v Then
                If Cells(i, 5) = "" Then
                   Cells(i, 5) = Cells(j, 2)
                Else
                    Cells(i, 5) = Cells(i, 5) & "," & Cells(j, 2)
                End If
            End If
        Next j
        Next i

End Sub

例如:

在此处输入图像描述

于 2017-10-26T13:14:36.477 回答