合并重复的单元格,并在其他列合并值

对不起,我是VBA新手。 我试图寻找相关的答案,但没有解决我所需要的。 我有许多列的数据列表。 基本上我想合并列B中相同的单元格,然后合并所有其他唯一值(从列C到X)在同一张表

之前

非常感谢你!

我会使用scripting.dictionary来做到这一点。

您将不得不修改范围和表名称以适应。 如果你要超过1000行的数据,还需要处理数组的大小。

 Sub dave() Dim dicKey As String Dim dicValues As String Dim dic Dim data Dim x(1 To 1000, 1 To 24) Dim j As Long Dim count As Long Dim lastrow As Long lastrow = Cells(Rows.count, 1).End(xlUp).Row data = Range("A2:X" & lastrow) ' load data into variable With CreateObject("scripting.dictionary") For i = 1 To UBound(data) If .Exists(data(i, 2)) = True Then 'test to see if the key exists x(count, 3) = x(count, 3) & ";" & data(i, 3) x(count, 5) = x(count, 5) & ";" & data(i, 5) x(count, 8) = x(count, 8) & ";" & data(i, 8) x(count, 9) = x(count, 9) & ";" & data(i, 9) Else count = count + 1 dicKey = data(i, 2) 'set the key dicValues = data(i, 2) 'set the value for data to be stored .Add dicKey, dicValues For j = 1 To 24 x(count, j) = data(i, j) Next j End If Next i End With Sheets("Sheet2").Cells(2, 1).Resize(count - 1, 9).Value = x End Sub