|
- Sub Main()
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- '删除多余表
- For Each Sh In Sheets
- If Sh.CodeName = "Sheet1" Then
- ElseIf Sh.CodeName = "Sheet17" Then
- Else
- Sh.Delete
- End If
- Next
- '计算拆分表数量
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- d.CompareMode = vbTextCompare
- ar = Sheet1.Range("E1", Sheet1.Range("E65536").End(3)).Value
- For i = 3 To UBound(ar)
- If Len(ar(i, 1)) > 0 Then
- If Not d.exists(ar(i, 1)) Then Set d(ar(i, 1)) = CreateObject("scripting.dictionary")
- d(ar(i, 1)).Add i, i
- End If
- Next
- '排序
- With Sheet1
- .Range("P:P").Clear
- .Range("P1").Resize(d.Count) = Application.Transpose(d.keys)
- .Range("P:P").Sort .Cells(1, "P"), xlAscending, , , , , , xlNo
- br = .Range("P1").Resize(d.Count)
- .Range("P:P").Clear
- r = .Cells(65536, 5).End(3).Row
- ar = .Range("A1:M" & r).Value
- End With
- '拆分
- For i = 1 To UBound(br)
- Set dic = d(br(i, 1) & "")
- Set Sh = Sheets.Add(Before:=Sheet17)
- Sh.Name = br(i, 1) & "#"
- Sheet1.Range("A:N").Copy Sh.Range("A1")
- For j = r To 3 Step -1
- If Not dic.exists(j) Then Sh.Rows(j).Delete
- Next
- Next
- MsgBox "完成"
- Set d = Nothing
- Application.ScreenUpdating = True
- Application.DisplayAlerts = True
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|