+ Reply to Thread
Results 1 to 22 of 22

Code to copy data from multiple sheets into one final output sheet.

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Code to copy data from multiple sheets into one final output sheet.

    Morning,

    I need to copy some data from 4 tab sheets into one final sheet as a final part of my macro;

    Sheet names are;

    Original Data
    A200
    A210
    A220

    I need the used range of these sheets to be copied and pasted together on the 'Final Output' tab.

    Any ideas on what my code would be?

  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: Code to copy data from multiple sheets into one final output sheet.

    Will the Final Output tab already have the headers in it?

    If you run the macro once and want to run it again, should the output from the 1st run be cleared and fresh data input?

    Do you need the sheetname from where the data was copied to be shown in a column of the Final Output sheet?
    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
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    No the headers won't be there, yes it would be good once all the data has been copied to the Final Ouput sheet, the other sheets are cleared ready to run another set of data./..

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    Ok, the other sheets can be cleared.

    But if you have run the macro one time and the data has been consolidated into the Final Output sheet, then you realise that the data has some error (just an example) and you need to run the macro again. When you run the macro the 2nd time, should the data that is already present in the Final Output sheet be cleared and then the data consolidated again?

  5. #5
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    Yes that would be great...

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    So to confirm, the macro will delete the contents of the Final Output sheet and refill with data.

    Once the data has been consolidated, it will clear the contents of the 4 source sheets as well.

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    Yes once the macro has run, consolodated the data across Original Data, A200, A220, A240, it will copy the data from these 4 tabs and populate the Final Output sheet and clear down the other 4 tabs.

    It maybe worth while adding something at the start of the macro to clear the 5 tabs prior to running....

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    It maybe worth while adding something at the start of the macro to clear the 5 tabs prior to running....
    If the source sheets are cleared prior to running the macro, how would the macro consolidate it?

    Wouldnt it be better to clear the source files after running the macro and the final output file before?

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    I meant, it could be worthwhile for the macro to clear the sheets prior to requesting the file, in case there is data there from a previous run.

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    So you would like to merge the consolidation code with the code from post 72 of this thread - http://www.excelforum.com/excel-prog...-values-5.html ?

    So do you want to consolidate the data after opening the file as per the macro?

    ---------- Post added at 04:38 PM ---------- Previous post was at 04:33 PM ----------

    This is the code to consolidate.
    Please Login or Register  to view this content.
    This code clears the contents of the Final Output sheet before running the macro. Once you explain the other stuff, i can help you change it to what you need.

  11. #11
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    Does the code you have given above copy all data from the 4 tabs and paste it into the final output?

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    Yes, try it and let me know what needs to be changed.

    I have put some comments after the code.

  13. #13
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    Doesn't like this bit

    Please Login or Register  to view this content.
    Not sure where the mysheet is!!!!

  14. #14
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    this is now my full code;

    Please Login or Register  to view this content.

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    Mysheet is nothing but an array. So first, it will consolidate the data from original data, then from the other 3 sheets.

    Change these lines from
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    Also, put this bit of code before this line
    Please Login or Register  to view this content.
    . Remove it from where you have currently put it.

  16. #16
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    This better;

    Please Login or Register  to view this content.

  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: Code to copy data from multiple sheets into one final output sheet.

    As per the change i suggested, this is the final code that you can use -
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    Doesnt like this bit of this line;

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Error message is - Sub or Function not defined

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

    Re: Code to copy data from multiple sheets into one final output sheet.

    Oops...just add a "." in between.

    It has to be Thisworkbook.Worksheets

  20. #20
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: Code to copy data from multiple sheets into one final output sheet.

    Works a treat, one other question, i have this code;

    Please Login or Register  to view this content.
    but i still get a pop up about links to other data sources, how do i stop this using code?

  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: Code to copy data from multiple sheets into one final output sheet.

    I dont think you can stop that.

  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: Code to copy data from multiple sheets into one final output sheet.

    Is this thread solved?

+ 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