|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub 按班级合并()
- Dim arr, i&, d As Object, key$, Rng As Range
- Set d = CreateObject("Scripting.Dictionary")
- arr = Sheet1.Range("A1").CurrentRegion
- For i = 2 To UBound(arr)
- key = arr(i, 1) & "|" & arr(i, 2)
- If Not d.Exists(key) Then
- d(key) = arr(i, 3)
- Else
- d.Item(key) = d.Item(key) & "、" & arr(i, 3)
- End If
- Next
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Sheet2.Select
- Range("A2:C1000").UnMerge
- Range("A2:C1000").ClearContents
- Range("A2").Resize(d.Count, 3) = WorksheetFunction.Transpose(Array(d.keys, d.keys, d.items))
- Range("A:A").Replace "|*", ""
- Range("B:B").Replace "*|", ""
- For Each Rng In Range("A2:A" & d.Count)
- If Rng.Value = Rng.Offset(1, 0) Then
- Rng.Resize(2, 1).Merge
- End If
- Next
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|