|
- Sub 拆分工作表()
- Dim Sht As Worksheet
- Dim arr, m&, n%, Str
- Dim dic As Object
- Set dic = CreateObject("Scripting.Dictionary")
- With Worksheets("销售总表")
- arr = .Range("A1").CurrentRegion
- For m = 2 To UBound(arr, 1)
- If Not dic.Exists(arr(m, 7)) Then
- Set dic(arr(m, 7)) = .Range("A1:I1")
- End If
- Set dic(arr(m, 7)) = Union(dic(arr(m, 7)), .Range("A" & m & ":I" & m)) '写在此处才能完整的记录所有数据
- Next
- End With
- Application.ScreenUpdating = False
- For Each Str In dic.keys
- On Error Resume Next
- Set Sht = Worksheets(Str)
- If Sht Is Nothing Then
- With Worksheets.Add(After:=Worksheets(Sheets.Count))
- .Name = Str
- dic(Str).Copy .Range("A1")
- End With
- Else
- dic(Str).Copy Sht.Range("A1")
- End If
- Set Sht = Nothing
- Next
- Worksheets("销售总表").Activate
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|