|
Sub 生成表()
Application.ScreenUpdating = False
Dim dic As Object, arr, i, j
Set dic = CreateObject("scripting.dictionary")
arr = Sheets("数据").UsedRange
For i = 2 To UBound(arr)
If Len(arr(i, 3)) Then
If Not dic.exists(arr(i, 3)) Then
Set dic(arr(i, 3)) = CreateObject("scripting.dictionary")
For j = 1 To UBound(arr, 2)
dic(arr(i, 3))(arr(1, j)) = arr(i, j)
Next
End If
End If
Next
Set Rng = Sheets("模板").UsedRange
Rng.Copy
brr = Sheets("模板").UsedRange
For Each ikey In dic.keys
Sheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = ikey
For i = 2 To UBound(brr)
For j = 1 To 10 Step 2
If dic(ikey).exists(brr(i, j)) Then
brr(i, j + 1) = dic(ikey)(brr(i, j))
End If
Next
Next
With ActiveSheet.[a1].Resize(UBound(brr), UBound(brr, 2))
.Value = brr
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteColumnWidths
End With
Next
Application.ScreenUpdating = True
End Sub
Sub 删除()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each sht In Worksheets
If sht.Name <> "数据" And sht.Name <> "模板" Then sht.Delete
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub |
|