|
- Sub Macro1()
- On Error Resume Next
- Dim arr, d, i&, j%
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For i = Sheets.Count To 1 Step -1
- If Sheets(i).Name <> "基础表" Then Sheets(i).Delete
- Next
- arr = Sheet1.Range("a1").CurrentRegion
- Set d = CreateObject("scripting.dictionary")
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 3)) Then d(arr(i, 3)) = i Else d(arr(i, 3)) = d(arr(i, 3)) & "," & i
- Next
- a = d.keys: b = d.items
- For i = 0 To d.Count - 1
- x = Split(b(i), ",")
- If Sheets(a(i)) Is Nothing Then
- With Sheets.Add(after:=Sheets(Sheets.Count))
- Sheet1.Rows(1).Copy .[a1]
- For j = 0 To UBound(x)
- Sheet1.Cells(x(j), 1).Resize(1, UBound(arr, 2)).Copy .Cells(j + 2, 1)
- Next
- .Name = "基础表-" & a(i)
- End With
- End If
- Next
- Sheet1.Activate
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|