|
Option Explicit
Sub TEST()
Dim ar(3 To 4), br, i&, j&, k&, r&, dic As Object, vKey
Dim Rng As Range, wks As Worksheet, t#, iPosRow&, iRowCount&
DoApp False
Set dic = CreateObject("Scripting.Dictionary")
Set wks = Sheets("模板")
t = Timer
For i = 3 To 4
ar(i) = Sheets(i).[A1].CurrentRegion
Next i
For i = 2 To UBound(ar(3)): dic(ar(3)(i, 7)) = "": Next
With Workbooks.Add
For Each vKey In dic.keys
wks.Copy after:=.Sheets(.Sheets.Count)
With .ActiveSheet
.Name = vKey
For i = 4 To 3 Step -1
ReDim cr(1 To UBound(ar(i)), 1 To UBound(ar(i), 2) + 1)
r = 0
For j = 2 To UBound(ar(i))
If ar(i)(j, 7) = vKey Then
r = r + 1
For k = 1 To UBound(ar(i), 2)
cr(r, k + 1) = ar(i)(j, k)
Next k
cr(r, 1) = r
End If
Next j
iPosRow = IIf(i = 4, 11, 4)
iRowCount = IIf(i = 4, 10, 5)
If r > iRowCount Then
For j = 1 To r - iRowCount
.Rows(iPosRow + 1).Insert Shift:=xlDown
Next j
End If
.Cells(iPosRow, 1).Resize(r, UBound(cr, 2)) = cr
Next i
End With
Next vKey
For Each wks In .Sheets
If wks.Name Like "*Sheet*" Then wks.Delete
Next
End With
Set dic = Nothing: Set wks = Nothing
DoApp
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.00") & " 秒", 64
End Sub
Function DoApp(Optional b As Boolean = True)
With Application
.ScreenUpdating = b
.DisplayAlerts = b
.Calculation = -b * 30 - 4135
End With
End Function
|
评分
-
1
查看全部评分
-
|