+ Reply to Thread
Results 1 to 3 of 3

Need help modifying a macro to open up workbooks and paste filtered data

Hybrid View

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    2

    Need help modifying a macro to open up workbooks and paste filtered data

    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

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Need help modifying a macro to open up workbooks and paste filtered data

    So is there data already in the "Item" workbook in Sheet1?

    Do you have a sample file that you can upload?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    Chicago
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Need help modifying a macro to open up workbooks and paste filtered data

    Here is a sample. This is for District 789. My source file will have many different district #s in it. What I would like to do from the source document is copy district 789 source data, open up the previously saved district 789 workbook and paste the data to a new tab.

    Thanks for your help!
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1