加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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

(2023-09-24 11:35:55)
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

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有