+ Reply to Thread
Results 1 to 5 of 5

Copy rows from multiple sheets based on condition

  1. #1
    Registered User
    Join Date
    01-12-2012
    Location
    -- Outside USA --
    MS-Off Ver
    Excel XP
    Posts
    2

    Copy rows from multiple sheets based on condition

    Hello, I'm trying to copy all rows that meets the condition in column "B" from all sheets in the workbook to a new worksheet.
    The name of the new worksheet which is equal to the condition to be copied is defined on "setup" worksheet. Here is the code:

    Please Login or Register  to view this content.
    unfortunately the code besides creating a new worksheet does nothing, where did I go wrong? Any help will be appreciated.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Copy rows from multiple sheets based on condition

    Can you attach a sample workbook?
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Registered User
    Join Date
    01-12-2012
    Location
    -- Outside USA --
    MS-Off Ver
    Excel XP
    Posts
    2

    Re: Copy rows from multiple sheets based on condition

    Hello Arkadi, sorry for a late reply
    Yes, here I attach a file
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Copy rows from multiple sheets based on condition

    There are many approach to get the data. Filter would be the best option, but since you have already set up a loop, I have adjusted the code, but it is not completed. What happens if the sheet already existed? Do you want to use the same sheet and clear the existing data or do you want to delete it? The code will error if the sheet already existed, so I have added a line to avoid the error. I suspect you want to loop over column G, not just single cell B4 as you have now. You can change the range name in to column G, so that the code loops through each cell and create sheet for each name.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-29-2016
    Location
    moscow
    MS-Off Ver
    2013
    Posts
    1

    Re: Copy rows from multiple sheets based on condition

    AB33 thank you for a solution.
    However, as you said filter is a way faster and better solution. Here I attach a file with comparison of both methods.
    As compiled sheets are generated from existing data, they are safe to delete, the approach is to test prior copying existence of such sheets and delete them if they exist.
    Speed tests are as follows: to compile 400 rows (200 + 200) by the loop is about 10 s, by filter approach is about 1 s.
    However it is nice to know that loop is also possible and may set to solve other tasks.
    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)

Similar Threads

  1. [SOLVED] Copy between sheets based on condition
    By justmatt in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-17-2014, 03:39 PM
  2. Refering certain rows in other sheets based on a particular condition
    By werunom in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-20-2013, 11:32 PM
  3. Refering certain rows in other sheets based on a particular condition
    By werunom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2013, 09:32 PM
  4. Copy Rows to Sheets Based on Condition
    By chcampbell12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2013, 12:42 PM
  5. copy rows from multiple worksheets to a new condition based on criteria
    By TheVoodoo in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-20-2012, 02:37 PM
  6. Excel Macro to insert two rows based on condition and copy and paste multiple cells
    By mannabhalo in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-13-2012, 12:56 PM
  7. How to copy columns to new sheets based on condition?
    By babayaga123 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2008, 09:54 PM

Tags for this Thread

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