|
Sub 拆分()
Application.ScreenUpdating = False
Dim ar As Variant
Dim br(), cr()
Dim r As Long
Application.SheetsInNewWorkbook = 1
For Each sh In ThisWorkbook.Worksheets
m = m + 1
ar = sh.[a1].CurrentRegion
n_1 = 0: n_2 = 0
ReDim br(1 To UBound(ar), 1 To UBound(ar, 2))
ReDim cr(1 To UBound(ar), 1 To UBound(ar, 2))
For i = 2 To UBound(ar)
If Trim(ar(i, 2)) = "" Then
n_1 = n_1 + 1
For j = 1 To UBound(ar, 2)
br(n_1, j) = ar(i, j)
Next j
Else
n_2 = n_2 + 1
For j = 1 To UBound(ar, 2)
cr(n_2, j) = ar(i, j)
Next j
End If
Next i
If n_2 > 0 Then
n_1 = n_1 + 1
br(n_1, 1) = "个人"
For j = 3 To 5
br(n_1, j) = Application.Sum(Application.Index(cr, 0, j))
Next j
End If
If n_1 > 0 Then
If m = 1 Then
Set wb = Workbooks.Add
With wb.Worksheets(1)
.Name = sh.Name & "拆1"
.[a1].Resize(1, UBound(ar, 2)) = ar
.[a2].Resize(n_1, UBound(br, 2)) = br
.[a2].Resize(n_1, UBound(br, 2)).Borders.LineStyle = 1
End With
Else
Set sht = Worksheets.Add(after:=wb.Sheets(wb.Sheets.Count))
With wb.ActiveSheet
.Name = sh.Name & "拆1"
.[a1].Resize(1, UBound(ar, 2)) = ar
.[a2].Resize(n_1, UBound(br, 2)) = br
.[a2].Resize(n_1, UBound(br, 2)).Borders.LineStyle = 1
End With
End If
If n_2 > 0 Then
Set sht = Worksheets.Add(after:=wb.Sheets(wb.Sheets.Count))
With wb.ActiveSheet
.Name = sh.Name & "拆2"
.[a1].Resize(1, UBound(ar, 2)) = ar
.[a2].Resize(n_2, UBound(br, 2)) = cr
.[a2].Resize(n_2, UBound(br, 2)).Borders.LineStyle = 1
End With
End If
End If
Next sh
wb.SaveAs Filename:=ThisWorkbook.Path & "\拆分结果" & Format(Date, "yyyymmdd") & ".xlsx"
wb.Close
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
评分
-
2
查看全部评分
-
|