|
- Sub 按钮1_Click()
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("scripting.dictionary")
- Set dn = CreateObject("scripting.dictionary")
- arr = Sheets("工资明细").[a1].CurrentRegion
- Set sh = Sheets("汇总明细")
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- For j = 2 To UBound(arr)
- If Not d.exists(arr(j, 1)) Then
- Set d(arr(j, 1)) = Union([a1:d1], Cells(j, 1).Resize(1, 4))
- Else
- Set d(arr(j, 1)) = Union(d(arr(j, 1)), Cells(j, 1).Resize(1, 4))
- End If
- dn(arr(j, 2)) = ""
- Next j
- For j = 0 To dn.Count - 1
- sfolder = ThisWorkbook.Path & "" & dn.keys()(j)
- If Not fso.FolderExists(sfolder) Then
- fso.CreateFolder sfolder
- End If
- Next j
- Sheets.Add after:=Sheets(2)
- For j = 0 To d.Count - 1
- With ThisWorkbook.Sheets(3)
- .UsedRange.Clear
- d.items()(j).Copy .[a1]
- nm = .Cells(2, 2)
- .Copy
- With ActiveWorkbook
- .Sheets(1).Name = "工资明细"
- sh.Copy after:=.Sheets(1)
- arr = ActiveSheet.UsedRange
- Set Rng = Nothing
- For i = 2 To UBound(arr)
- If arr(i, 1) <> d.keys()(j) Then
- If Rng Is Nothing Then
- Set Rng = Cells(i, 1)
- Else
- Set Rng = Union(Rng, Cells(i, 1))
- End If
- End If
- Next i
- If Not Rng Is Nothing Then Rng.EntireRow.Delete
- .SaveAs ThisWorkbook.Path & "" & nm & "" & d.keys()(j) & ".xlsx"
- .Close False
- End With
- End With
- Next j
-
- ThisWorkbook.Activate
- Sheets(3).Delete
- Sheets(1).Select
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|