I am using the code below to split a worksheet into multiple workbooks and it works great. Now, what I need to do is to modify this code to perform the same function on a different spreadsheet. I need the data filtered, but instead of saving the filtered data to a new workbook, I need it to open the file with the "Item" name and paste the different data to a new sheet - "Sheet2".
Basically, I only want one workbook per "Item" of data - each workbook would have 2 sheets. Can anyone assist with this?
![]()
Sub YSI3Splits() Dim Sh As Worksheet Dim Rng As Range Dim c As Range Dim List As New Collection Dim Item As Variant Dim WB As Workbook Application.ScreenUpdating = False Set Sh = Worksheets("Sheet1") Set Rng = Sh.Range("A2:A" & Sh.Range("A65536").End(xlUp).Row) On Error Resume Next For Each c In Rng List.Add c.Value, CStr(c.Value) Next c On Error GoTo 0 Set Rng = Sh.Range("A1:Z" & Sh.Range("A65536").End(xlUp).Row) For Each Item In List Set WB = Workbooks.Add Rng.AutoFilter Field:=1, Criteria1:=Item Rng.SpecialCells(xlCellTypeVisible).Copy WB.Worksheets(1).Range("A1") Rng.AutoFilter With WB .SaveAs Filename:= _ "c:\users\prest\documents\Test" & "\" & Item & " 2012 Splits " & Format(Now(), "MM-YY") & ".xlsx" .Close End With Next Item Sh.Activate Application.ScreenUpdating = True End Sub
Bookmarks