如何将筛选内容自动另存为工作簿
第1块, 产生分表
Sub TT()
Dim Cel As Range, Res
Dim i, a As Integer
Set d = CreateObject("Scripting.Dictionary")
For Each Cel In Range("C2:C" & ThisWorkbook.Worksheets("sheet1").Range("c65536").End(xlUp).Row)
If Cel <> "" Then
If Not d.exists(Cel.Value) Then d.Add Cel.Value, Cel.Value
End If
Next
Res = d.Items
For i = 0 To d.Count - 1
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = Res(i)
ActiveSheet.Cells(1, 1) = Worksheets("sheet1").Cells(1, 1)
ActiveSheet.Cells(1, 2) = Worksheets("sheet1").Cells(1, 2)
ActiveSheet.Cells(1, 3) = Worksheets("sheet1").Cells(1, 3)
a = 2
With Worksheets(1).Range("C1:C" & Worksheets(1).Range("c65536").End(xlUp).Row)
Set c = .Find(Res(i), LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
ActiveSheet.Cells(a, 1) = Worksheets(1).Cells(c.Row, 1).Value
ActiveSheet.Cells(a, 2) = "'" & Worksheets(1).Cells(c.Row, 2).Value
ActiveSheet.Cells(a, 3) = Res(i)
a = a + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
Next i
Worksheets(1).Select
End Sub
复制代码
第2块,产生单独的文件.
Sub AA()
Dim i As Integer, nn As String
If Sheets.Count = 1 Then
MsgBox "You haven't generated seperated sheets."
Exit Sub
Else
For i = 2 To Sheets.Count
nn = Sheets(i).Name
Sheets(i).Select
Sheets(i).Copy
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & nn & ".xls", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Next i
End If
Worksheets(1).Select
End Sub
复制代码