|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Dim dic As Object
- Sub 分解成表()
- Dim dd
- Application.ScreenUpdating = False
- Call 删除工作表
- Call 提取分类
- With ThisWorkbook
- For Each dd In dic.Keys
- With .Worksheets.Add(After:=Worksheets(Sheets.Count))
- .Name = dd
- dic.Item(dd).Copy .Range("A1")
- .Columns("A:Z").EntireColumn.AutoFit
- End With
- Next
- .Worksheets("Sheet1").Activate
- End With
- Set dic = Nothing
- Application.ScreenUpdating = True
- End Sub
- Sub 分解成簿()
- Dim dd, wBook As Workbook
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Call 提取分类
- Application.SheetsInNewWorkbook = 1
- For Each dd In dic.Keys
- Set wBook = Workbooks.Add '新建工作簿
- With wBook
- With .Worksheets(1)
- .Name = dd
- dic(dd).Copy .Range("A1") '此处直接复制、粘贴带有单元格格式的数据。
- .Columns("A:Z").EntireColumn.AutoFit
- End With
- .SaveAs Filename:=ThisWorkbook.Path & "" & dd
- .Close False
- End With
- Next
- Set dic = Nothing
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
- Function 删除工作表()
- Dim Sht As Worksheet
- Application.DisplayAlerts = False
- For Each Sht In ThisWorkbook.Worksheets
- If Sht.Name <> "Sheet1" Then
- Sht.Delete
- End If
- Next
- Application.DisplayAlerts = True
- End Function
- Function 提取分类()
- Dim arr, m%, n%, Str$
- Set dic = CreateObject("Scripting.Dictionary")
- arr = Sheet1.Range("A1").CurrentRegion
- With Worksheets("Sheet1")
- For m = 2 To UBound(arr, 1)
- If arr(m, 5) = "户主" Then
- Str = arr(m, 2) & "+" & arr(m, 3)
- 'If Not dic.Exists(Str) Then
- Set dic(Str) = .Range(.Cells(1, 1), .Cells(1, UBound(arr, 2)))
- Set dic(Str) = Union(dic(Str), .Range(.Cells(m, 1), .Cells(m, UBound(arr, 2))))
- 'End If
- Else
- Set dic(Str) = Union(dic(Str), .Range(.Cells(m, 1), .Cells(m, UBound(arr, 2))))
- End If
- Next
- End With
- End Function
复制代码 |
|