Consulting

Results 1 to 8 of 8

Thread: Filter - Copy - Paste

  1. #1
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    3
    Location

    Filter - Copy - Paste

    Hello R1C1,

    I am beginner in excel VBA coding and found a problem related to this, I am having a sheet where the data is available state wise, and i want to put a code which will help to filter the data state wise and copy the selected data and paste into new excel workbook and then save the same from the name of that state in specific folder and repeat the same action for rest of the data until it's covered all the filtered data.

    Your help will be a breakthrough to save my job.

    Thanks,
    Pranav Sharma

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    You are posting to a 12 year old topic with a title that doesn't seem to apply to your question

    You'd get more visibility if you create a new topic with a more appropriate title
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    These first three posts moved from:
    http://www.vbaexpress.com/forum/show...ath#post377894
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  4. #4
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Sub test()
        Dim r As Range
        Dim c As Range
        Dim p As String
        
        Set r = Range("A1").CurrentRegion
        Set c = r(1).Offset(, r.Columns.Count + 1)
        
        p = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\*****\"
        
        r.Columns(1).AdvancedFilter xlFilterCopy, , c, True
        Do While c.Offset(1).Value <> ""
            With Workbooks.Add(xlWBATWorksheet)
                r.AdvancedFilter xlFilterCopy, c.Resize(2), .Sheets(1).Range("A1")
                .SaveAs p & c.Offset(1).Value & ".xlsx", xlOpenXMLWorkbook
                .Close False
            End With
            c.Offset(1).Delete xlShiftUp
        Loop
        c.Resize(2).ClearContents
        
    End Sub

    マナ

  5. #5
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    3
    Location
    Attaching the excel, if you can help to put a code in VBA for this will be very thankful. In attached excel I want to filter the data from column F "Brand"and then select 1 by 1 each brand and copy the data and paste into new excel and save into a specific folder with the same name of the brand on my desktop. And the same action keep on continue until the all brands are completed.
    Attached Files Attached Files

  6. #6
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    r.Columns("F").AdvancedFilter xlFilterCopy, , c, True

  7. #7
    VBAX Newbie
    Joined
    Mar 2018
    Posts
    3
    Location
    Yes, auto filter need to put on column "F" and macro will copy and paste the data brand wise into new excel with the same brand name in specific folder.

  8. #8
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    >in specific folder.

    p = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\*****\"

Posting Permissions

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