+ Reply to Thread
Results 1 to 34 of 34

Extract from multiple worksheets based on one condition and output to new workbook

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Extract from multiple worksheets based on one condition and output to new workbook

    Hello,

    I am trying to create a button that generates 3 reports based on one condition. Please see the attached file.

    There are 3 tables to be generated, namely, worksheet A, B and C.

    In worksheet A, there is a master button, "Generate quarter report". I would like to first select a specific quarter(Q 1, Q 2, Q 3 or Q 4) from the dropdown list in cell D2, and hit that master button. The purpose of the button is to filter all of the records from three worksheets based on that quarter selection and output the 3 worksheet recordsets to a new workbook.

    Additionally, I would like the new workbook to be able to prevent users from modifying records in the output files by default. (simply just want to have columns locked)

    Is this possible?

    Thank you
    Attached Files Attached Files

  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: Extract from multiple worksheets based on one condition and output to new workboo

    Your request is not very clear. All i see in tabs A B and C is Q1, Q2, etc & P1, P2 etc. There is no data available.
    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
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Quote Originally Posted by arlu1201 View Post
    Your request is not very clear. All i see in tabs A B and C is Q1, Q2, etc & P1, P2 etc. There is no data available.
    Oops sorry.

    Please see the attached with more fields.

    So basically, when the button is clicked, I would like to have Excel filter on all worksheets based on either the period selection OR the quarter selection, depending on what user's needs are, and then output the filtered recordsets to a new workbook.

    The generated files in the new workbook just need to contain all 4 original columns, so data in this context means everything you see from Col A to Col D.

    Please see the attached file

    Thanks
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi, could you respond to my subsequent post when you get a chance? Is it possible?

    Thank you

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hey Lifeseeker,

    I guess many were away for the christmas vacations so your post remain un-answered. Do you still need a resolution?

  6. #6
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Quote Originally Posted by arlu1201 View Post
    Hey Lifeseeker,

    I guess many were away for the christmas vacations so your post remain un-answered. Do you still need a resolution?
    Hi,

    Yes please. Happy New Year first!

    What I would like:

    To have a button that when clicked, filters all records based specified quarter and export the filtered recordset to a new workbook with same properties. (for example, if columns are locked, i want the exported table to have the same property)

    Is this clear?

    Thank you
    Attached Files Attached Files

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Just one last question - I understand that there will be 3 sheets with data- A, B and C which needs to be filtered. Should the records be exported to 3 different worksheets of the new workbook? Or should it be exported to the same worksheet of the new workbook?

  8. #8
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Quote Originally Posted by arlu1201 View Post
    Just one last question - I understand that there will be 3 sheets with data- A, B and C which needs to be filtered. Should the records be exported to 3 different worksheets of the new workbook? Or should it be exported to the same worksheet of the new workbook?
    Hi,

    Actually....would it be possible to export to 3 different workbooks where each new workbook just contains one table? So workbookA will store A, new workbookB will store B, etc.

    If this is not possible, then 3 different worksheets of the new workbook please.

    Thank you

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Both are possible. You just tell me which will be your preference -
    A - Export to different workbooks
    B - Export to different worksheets

  10. #10
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    A please, different workbooks.

    Thank you

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    You can use this code. It creates 3 new workbooks with the required headers and copies the data over. Sheet1 data from the main file goes to workbook by name of Bk1, Sheet2 to Bk2, etc. This is automated and if you need to change it to something specific let me know.
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi,

    Thank you for doing this.

    I am getting an error: "subscript out of range" on
    Please Login or Register  to view this content.
    i thought I didn't have to activate this workbook for it to recognize?

    i am also attaching the file.

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    I actually didnt use this file that you provided. Since you said that the data belonged to 3 different worksheets, i had copied the data in sections A, B and C in your Master file to another file with 3 worksheets. Those worksheets were named, Sheet1, Sheet2 and Sheet3.
    If you will be using this file, the code will need to be changed to some extent, as there wont be 3 sheets but 1 having all the 3 datasets in it.

    The line that gave you the error is the one that was creating the header in the new workbook. If you do not want to use that code line, we can hard-code the headers as
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Ah I see. I'm sorry for not being 100% clear...

    Would it be possible if all 3 recordsets are in 1 worksheet as the way it is(this file), but when I do the filter and export, I would like to have 3 recordsets( A B and C) be in 3 different workbooks as opposed to 3 different worksheets?

    As you can see, all recordsets have exactly the same format, which would be easy.

    So after the export is done, that recordset table A will be in workbook A, table B will be in workbook B, etc. I want like to keep them separate please.

    Please see the attached.

  15. #15
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Is anyone able to assist?

  16. #16
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    Are you able to help with the request?

    Thanks

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Use this code -
    Please Login or Register  to view this content.

  18. #18
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    few issues.

    When I run the code, it says bk1 already exists in the location. Do you want to replace it?

    And if I hit "yes", then I get "subscript out of range" error and code

    Please Login or Register  to view this content.
    is highlighted.

    If I hit "No", I got workbook saveas method failed and code highlighted is:
    Please Login or Register  to view this content.
    please see the attached.

    Any ideas?

  19. #19
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    Are you able to help?

    Thanks

  20. #20
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Is anyone able to assist?

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Checking on it right now LifeSeeker.

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    I checked the code and it works fine. Just add these 2 lines at the beginning of the code -
    Please Login or Register  to view this content.
    Use the same 2 lines before the End Sub at the end of your code, change False to True.

  23. #23
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    I still run into errors on this one..

    Would you mind checking the code in the file?

    You get no errors at all?

    I keep getting the subscript out of range error this time after I click on the button. Error line is on
    Please Login or Register  to view this content.
    Thank you for your time.

    Please Login or Register  to view this content.

  24. #24
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Is anyone able to assist please?

    Thanks

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Use this updated code -
    Please Login or Register  to view this content.

  26. #26
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    hmm this time I do see three workbooks being opened.

    However, there are no values contained in the new workbook.

    For example, I picked Q3 in the "Master", and after Excel opened 3 workbooks and I went in and see, I would have expected that all the Q3 rows appear in each of the workbook, but only the header column is there.

    Do you get the same thing on your end or?

    Something is not working out right

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    When you had initially mentioned the requirement, you had said that both the dropdowns would be selected, so you will not see data unless the period dropdown is selected too. But i can change that. I will provide you the updated code shortly.

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Use this code -
    Please Login or Register  to view this content.

  29. #29
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    Actually....it is now working. I used your exact code.

    I must have done something wrong that I wasn't even aware. Anyway.

    by the way, is it possible to fine-tune the column format of the exported recordset?

    i see that the exported recordset doesn't have proper column width. like..you have to double click on column boundary to fine-tune.

    Also, is it possible to lock all the exported columns so that users don't modify the numbers in them?

    Thank you
    Last edited by Lifeseeker; 01-23-2012 at 02:31 AM. Reason: it's actually working..

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Regarding the column boundary, just put this code line
    Please Login or Register  to view this content.
    at the end before
    Please Login or Register  to view this content.
    Do you want to lock the exported columns via code?

  31. #31
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    Yes, that would be great if I could also have the record locked on the exported recordset.

    thank you!

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

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Use this code (updated) -
    Please Login or Register  to view this content.

  33. #33
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    A millions of thanks is not enough to express my gratitude.

  34. #34
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    513

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    A millions of thanks is simply not enough to express my gratitude.

+ 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