新浪博客

excel中第一列相同,合并第2列中相应单元格内容,并用顿号隔开

2023-09-24 11:35阅读:
Sub test()
Application.ScreenUpdating = False
n = 1
Set d = CreateObject('scripting.dictionary')
arr = [a1].CurrentRegion
For i = 1 To UBound(arr)
d(arr(i, 1)) = d(arr(i, 1)) & arr(i, 2) & '、'
Next
[e1].Resize(d.Count) = Application.Transpose(d.keys)
cnt = d.Count
k = d.items
d.RemoveAll
For j = 0 To cnt
On Error Resume Next

brr = Split(k(j), ',')
For m = 0 To UBound(brr)
d(brr(m)) = ''
Next
Cells(n, 'f') = Join(d.keys, ',')
Cells(n, 'F') = Left(Cells(n, 'f'), Len(Cells(n, 'f')) - 1)
n = n + 1
d.RemoveAll
Next
Cells(Rows.Count, 'F').End(3).Delete
Application.ScreenUpdating = False
End Sub

我的更多文章

下载客户端阅读体验更佳

APP专享