+ Reply to Thread
Results 1 to 9 of 9

VBA Code: Copying rows from multiple sheets

  1. #1
    Registered User
    Join Date
    10-11-2012
    Location
    N/a
    MS-Off Ver
    Excel 2010
    Posts
    19

    VBA Code: Copying rows from multiple sheets

    Hello,
    I'm trying to use VBA to copy rows that satisfy a certain 'If-Then' statement from multiple sheets in Excel onto one sheet. All of the sheets have the same columns and each set is one month in a year. I've gotten the code to work for one sheet but I need the next month's rows to be copied on to the final sheet relative to where the previous month's ended. The first month I've copied is 'April' and I am copying all of them onto a sheet titled 'Change Summary 1'. Here is my code thus far:

    Please Login or Register  to view this content.
    My biggest problem is making the next month show up relative to the month before it on the 'Change Summary 1' sheet. Any suggestions are appreciated, although please note that I am VERY new to VBA and don't quite fully understand it yet. Thank you in advance!
    Last edited by JBeaucaire; 10-11-2012 at 09:32 AM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: VBA Code: Copying rows from multiple sheets

    Can you upload a mockup workbook of what your wanting to do?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    10-11-2012
    Location
    N/a
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: VBA Code: Copying rows from multiple sheets

    Mockup Workbook.xlsm

    Sure thing, I've replaced most of the data with letters but left the dates to help see if it's copying what it needs to. The month of April should already be copied into the Change Summary 1 worksheet. I'd like to have the month of May's 'Yes' values to start copying directly under where April's stops, and then June after that and so on. I'd like to be able to use the same coding every year so I need to be relative to the previous month rather than just telling the program to start inputting at a specific line. Thanks for the help!

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: VBA Code: Copying rows from multiple sheets

    One question. Is the Summary Sheet to be cleared everytime before running the macro?

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: VBA Code: Copying rows from multiple sheets

    Give this a shot

    Please Login or Register  to view this content.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Code: Copying rows from multiple sheets

    This is what the AUTOFILTER was created for. It lets you apply a filter to a set of data to see just the rows that match a certain criteria. In this macro, we're applying the AutoFilter to column I for the word "Yes" then copying all the visible rows to the summary all at once.

    1) Right-click the Summary tab and select VIEW CODE
    2) Paste in this event macro:
    Please Login or Register  to view this content.
    3) Close the VBeditor
    4) Now click on any Month sheet, then click back the Summary. The "activation" macro given will trigger itself and recreate the Summary page new each time you do that.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: VBA Code: Copying rows from multiple sheets

    Or if you dont want the dropdowns added to the Summary sheet use this

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-11-2012
    Location
    N/a
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: VBA Code: Copying rows from multiple sheets

    The AutoFilter worked, however it did give me an error message after it worked saying "AutoFilter method of Range class failed". For whatever reason, the macro begins placing the data a column too far to the left, starting with column 'F'
    Last edited by Nctukek; 10-11-2012 at 10:05 AM.

  9. #9
    Registered User
    Join Date
    10-11-2012
    Location
    N/a
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: VBA Code: Copying rows from multiple sheets

    Mike, I tried your macro and as far as I can tell it worked perfectly! Thanks again for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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