完全根据你的“汇总”表写的代码,此代码会分拆数据后保存在“汇总”表的目录下 Sub SplitBook() Dim wb(2) As Workbook Dim Index As Byte, bytIdx(1) As Byte, bytCnt(1) As Byte, Criteria(2) As String, strName As String Application.ScreenUpdating = False Set wb(0) = Workbooks.Add Set wb(1) = Workbooks.Add Set wb(2) = Workbooks.Add bytCnt(0) = ThisWorkbook.Sheets.Count bytCnt(1) = wb(0).Sheets.Count If bytCnt(1) < 3 Then bytCnt(1) = bytCnt(0) - wb(0).Sheets.Count wb(0).Sheets.Add Count:=bytCnt(1) wb(1).Sheets.Add Count:=bytCnt(1) wb(2).Sheets.Add Count:=bytCnt(1) End If Criteria(0) = "地质工程组" Criteria(1) = "工区领导" Criteria(2) = "经营组" For bytIdx(0) = 1 To bytCnt(0) With ThisWorkbook.Sheets(bytIdx(0)) bytCnt(1) = .UsedRange.Rows.Count For Index = 0 To 2 .Cells(1, 2).AutoFilter Field:=2, Criteria1:=Criteria(Index) .Range(.Cells(1), .Cells(bytCnt(1), 12)).SpecialCells(xlCellTypeVisible).Copy _ wb(Index).Sheets(bytIdx(0)).Cells(1) Next strName = .Name For Index = 0 To 2 With wb(Index).Sheets(bytIdx(0)) .Name = strName .UsedRange.EntireColumn.AutoFit End With Next End With bytIdx(1) = bytIdx(1) + 1 Next For Index = 0 To 2 wb(Index).Close True, ThisWorkbook.Path & "\" & Criteria(Index) Next Erase wb Erase Criteria Erase bytIdx Erase bytCnt Application.ScreenUpdating = True End Sub |