|
汇总代码:
- Sub test2()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim ws As Worksheet
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("总表")
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(1, c)
- For j = 2 To UBound(arr, 2)
- d1(arr(1, j)) = j
- Next
- End With
- For Each ws In Worksheets
- If ws.Name <> "总表" Then
- With ws
- If .Range("a1") = "课程编号" And .Range("b1") = "课别" Then
- r = .Cells(.Rows.Count, 3).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- If r > 1 Then
- arr = .Range("a1").Resize(r, c)
- For j = 11 To UBound(arr, 2) - 4
- If Not d.exists(arr(1, j)) Then
- ReDim brr(1 To 21)
- brr(1) = arr(1, j)
- Else
- brr = d(arr(i, j))
- End If
- For i = 2 To UBound(arr)
- If d1.exists(arr(i, 3)) Then
- n = d1(arr(i, 3))
- brr(n) = arr(i, j)
- brr(n + 1) = arr(i, 5)
- End If
- Next
- d(arr(1, j)) = brr
- Next
- End If
- End If
- End With
- End If
- Next
- With Worksheets("总表")
- .UsedRange.Offset(1, 0).Clear
- With .Range("a2").Resize(d.Count, UBound(brr))
- .Value = Application.Transpose(Application.Transpose(d.items))
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 10
- End With
- End With
- End With
- End Sub
复制代码 |
|