|
- Sub 按钮1_Click()
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("scripting.dictionary")
- Set dn = CreateObject("scripting.dictionary")
- arr = Sheets("工资明细").[a1].CurrentRegion
- 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
- If Not dn.exists(arr(j, 2)) Then
- dn(arr(j, 2)) = arr(j, 1)
- Else
- If InStr(dn(arr(j, 2)), arr(j, 1)) = 0 Then
- dn(arr(j, 2)) = dn(arr(j, 2)) & "," & arr(j, 1)
- End If
- End If
- Next j
- For j = 0 To d.Count - 1
- Sheets.Add after:=Sheets(2)
- With Sheets(3)
- .Name = d.keys()(j)
- d.items()(j).Copy .[a1]
- r = .UsedRange.Rows.Count + 1
- .Cells(r, 1) = "合计"
- .Cells(r, 4) = WorksheetFunction.Sum(.Cells(2, 4).Resize(r))
- End With
- Next j
- For j = 0 To dn.Count - 1
- ThisWorkbook.Activate
- sfolder = ThisWorkbook.Path & "" & dn.keys()(j)
- If Not fso.FolderExists(sfolder) Then
- fso.CreateFolder sfolder
- End If
- If InStr(dn.items()(j), ",") > 0 Then
- brr = Split(dn.items()(j), ",")
- Sheets(Split(dn.items()(j), ",")).Copy
- Else
- Sheets(dn.items()(j)).Copy
- End If
- With ActiveWorkbook
- .SaveAs sfolder & "" & dn.keys()(j) & ".xlsx"
- .Close False
- End With
- Next j
- ThisWorkbook.Activate
- For j = Sheets.Count To 3 Step -1
- Sheets(j).Delete
- Next j
- Application.DisplayAlerts = True
- Application.ScreenUpdating = True
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|