|
积极参与学习下,不知道有没有达到你要的效果。
Sub 拆分()
Dim arr, brr(), a, b, c, d, e, f, g
Dim sh As Worksheet
Dim wk As Workbook
a = Worksheets("人员概况").Range("b1").Value
b = Worksheets("人员概况").Range("b2").Value
Application.DisplayAlerts = False
Set wk = Workbooks.Add
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "人员概况" Then
c = c + 1
g = 0
wk.Sheets(c).Name = sh.Name
With wk.Sheets(c)
.Columns("h:h").NumberFormatLocal = "yyyy/m/d"
.Columns("A:A").ColumnWidth = 6
.Columns("b:b").ColumnWidth = 10.5
.Columns("c:c").ColumnWidth = 19
.Columns("d:d").ColumnWidth = 26
.Columns("e:e").ColumnWidth = 30
.Columns("f:f").ColumnWidth = 25
.Columns("g:g").ColumnWidth = 9
.Columns("h:h").ColumnWidth = 13
End With
arr = sh.Range("a1").CurrentRegion
ReDim brr(1 To UBound(arr, 1), 1 To UBound(arr, 2))
For d = 1 To UBound(arr, 2)
wk.Worksheets(c).Cells(1, d) = arr(1, d)
If arr(1, d) = a Then e = d
Next
For f = 1 To UBound(arr, 1)
If arr(f, e) = b Then
g = g + 1
For d = 1 To UBound(arr, 2)
brr(g, d) = arr(f, d)
Next
End If
Next
wk.Sheets(c).Range("a2").Resize(UBound(brr, 1), UBound(brr, 2)) = brr
End If
Next
Erase arr: Erase brr
wk.SaveAs ThisWorkbook.Path & "\" & b & ".xlsx"
wk.Close
Application.DisplayAlerts = True
End Sub
|
|