+ Reply to Thread
Results 1 to 6 of 6

Extracting selected data into new worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2008
    Location
    Birmingham, UK
    MS-Off Ver
    Office 2007
    Posts
    43

    Extracting selected data into new worksheets

    I have a workbook, see attached example, which has multiple columns. I want to extract the data for a certain criteria, in this example column E "product".

    I then want to take all of the data in columns A to L for the chosen criteria e.g. product 1696 and place it in a new worksheet.

    I want to do this for every unique product. The example I have given only shows 2 products and limited rows, in reality I could have 50-60 products with hundreds of rows per product.

    Is there a way of achieving this?

    Many Thanks
    Attached Files Attached Files
    Last edited by dcaraher; 07-15-2009 at 12:02 PM.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Extracting selected data into new worksheets

    Try this:
    Sub Macro2()
     
    Dim rng As Range, rng2 As Range, ws As Worksheet
     
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    With Sheet1
        Sheets.Add().Name = "Temp"
        .Range("E1", .Range("E1").End(xlDown)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Sheets("Temp").Range("A1"), Unique:=True
        Set rng2 = Sheets("Temp").Range("A2", Sheets("Temp").Range("A2").End(xlDown))
         For Each rng In rng2
            .Range("A1").AutoFilter field:=5, Criteria1:=rng
            Set ws = Worksheets.Add(After:=Worksheets(Worksheets.Count))
            .AutoFilter.Range.Copy ws.Range("A1")
            ws.Name = rng
            .Range("A1").AutoFilter field:=1
        Next rng
        Sheets("Temp").Delete
        .AutoFilterMode = False
    End With
     
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Registered User
    Join Date
    12-04-2008
    Location
    Birmingham, UK
    MS-Off Ver
    Office 2007
    Posts
    43

    Re: Extracting selected data into new worksheets

    Stephen, that is excellent. I'm no expert in analysing the code but a quick question.

    Does this code work for unlimited product and unlimited number of rows/columns or will I need to adapt it if my ranges increase.

    Many Thanks

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Extracting selected data into new worksheets

    My pleasure.

    It should work for any amount of data and any number of products as long as your products remain in column E (the 5 in the AutoFilter line) and there are no completely blank rows in your data.

  5. #5
    Registered User
    Join Date
    12-04-2008
    Location
    Birmingham, UK
    MS-Off Ver
    Office 2007
    Posts
    43

    Re: Extracting selected data into new worksheets

    Stephen, That has ben so helpful thank you very much. How do I show this topic as solved?

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Extracting selected data into new worksheets

    For future reference, see "How To" at the top of the page.

    To mark your thread solved do the following:
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save

+ 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