|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("总表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a4:t" & r)
- End With
- For i = 1 To UBound(arr)
- If Not d.exists(arr(i, 20)) Then
- Set d(arr(i, 20)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 20)).exists(arr(i, 5)) Then
- m = 1
- ReDim brr(1 To 9, 1 To m)
- Else
- brr = d(arr(i, 20))(arr(i, 5))
- m = UBound(brr, 2) + 1
- ReDim Preserve brr(1 To 9, 1 To m)
- End If
- brr(1, m) = m
- For j = 3 To 7
- brr(j - 1, m) = arr(i, j)
- Next
- If arr(i, 20) = "转入" Then
- brr(7, m) = arr(i, 20)
- Else
- brr(8, m) = arr(i, 20)
- End If
- brr(9, m) = arr(i, 10)
- d(arr(i, 20))(arr(i, 5)) = brr
- Next
- For Each aa In d.keys
- For Each bb In d(aa).keys
- wjm = aa & bb
- On Error Resume Next
- Set ws = Worksheets(wjm)
- If Err Then
- Set ws = Worksheets.Add(after:=Worksheets(Worksheets.Count))
- ws.Name = wjm
- End If
- On Error GoTo 0
- With Worksheets(wjm)
- .Range("a6:i20").ClearContents
- arr = d(aa)(bb)
- ReDim brr(1 To UBound(arr, 2), 1 To UBound(arr))
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- brr(j, i) = arr(i, j)
- Next
- Next
- With .Range("a6").Resize(UBound(brr), UBound(brr, 2))
- .Value = brr
- With .Font
- .Size = 9
- .Name = "宋体"
- End With
- End With
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Next
- Next
-
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|