|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
参与一下。。。- Sub ykcbf() '//2024.1.24
- Dim arr, d
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- With Sheets("班别分类")
- r = .Cells(.Rows.Count, "b").End(xlUp).Row
- arr = .Range("a1:ag" & r)
- End With
- For i = 2 To UBound(arr)
- If arr(i, 1) = Empty Then arr(i, 1) = arr(i - 1, 1)
- For j = 3 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(1, j)
- d(s) = arr(i, j)
- s = arr(i, 1) & "|" & arr(i, 2)
- d1(s) = ""
- Next
- Next
- t = d.items
- ReDim zrr(1 To 10000, 1 To 2)
- For Each k In d1.keys
- b = Split(k, "|")
- m = m + 1
- zrr(m, 1) = b(0)
- zrr(m, 2) = b(1)
- Next
- With Sheets("打印")
- .UsedRange.Offset(6) = ""
- .UsedRange.Offset(6).UnMerge
- .[a7].Resize(m, 2) = zrr
- arr = .Range("a6:ag" & m + 5)
- For i = 2 To UBound(arr)
- For j = 3 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(i, 2) & "|" & arr(1, j)
- If d.Exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- With .Range("a6:ag" & m + 5)
- .Value = arr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- r = .Cells(Rows.Count, "a").End(xlUp).Row
- Dim rng As Range
- For i = r To 7 Step -1
- Set rng = Cells(i, "a")
- Set Rng1 = rng.Offset(-1)
- If rng = Rng1 Then
- Rng1.Resize(2).Merge
- End If
- Next
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|