+ Reply to Thread
Results 1 to 25 of 25

Copy Columns from Workbook to MasterWorkbook

  1. #1
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Copy Columns from Workbook to MasterWorkbook

    Scenario:

    I have 300+ workbooks. I need to copy columns C:LastActive (populated) column from the workbooks to a master workbook.

    Example:

    WB A ----> Copy from column C:LastPopulated to Master WB starting with the first blank column.

    So essentially, I have my master WB run the macro select the file and it will copy over. Rinse and repeat.

    Where do I start?

    Thanks.

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Copy Columns from Workbook to MasterWorkbook

    How many columns and rows are in each? is there only one tab per workbook?

    This shouldn't be very difficult to loop through, with basic code, but optimizing this would be to use ADO to grab it all, because it is REALLY fast and doesn't require you to open the workbooks at all.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Copy Columns from Workbook to MasterWorkbook

    So I am fairly new with VBA but the following was something I was working on recently for another project, I just modified it to make it work for your needs.

    ADO Extract - Batch Process.xlsb

    There are two macros here. One lists all files in the folder in range C5. So type the address of your folders there then hit LIST FILES. This will populate the file names to be used for the batch processing. I prefer to keep things separated so when things break I can figure out how and why faster.

    So once you have the files listed, Type YES in column F next to any files you want to extract data from. This is typically all of them for me, as I typically create a new folder to drop everything in to make sure this is as easy as possible.

    Once you have selected yes for them all, hit Process Everything Flagged as Yes. This will loop through all of the files, pulling the data into the Processing tab, then pasting/appending it to right of the data in the DATA tab, like you wanted.

    I created a few sample files to grab sample data from and it processed 100 files in 21 seconds so it should do 300 in about a minute.

    NOTE: you MUST enable macros, you must have the Microsoft ActiveX Data Objects 2.9 Library checked as an available reference.
    To do so use the following: http://msdn.microsoft.com/en-us/libr.../gg264402.aspx
    Last edited by mikeTRON; 01-17-2014 at 10:23 PM.

  4. #4
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by mikeTRON View Post
    So I am fairly new with VBA but the following was something I was working on recently for another project, I just modified it to make it work for your needs.

    Attachment 290904

    There are two macros here. One lists all files in the folder in range C5. So type the address of your folders there then hit LIST FILES. This will populate the file names to be used for the batch processing. I prefer to keep things separated so when things break I can figure out how and why faster.

    So once you have the files listed, Type YES in column F next to any files you want to extract data from. This is typically all of them for me, as I typically create a new folder to drop everything in to make sure this is as easy as possible.

    Once you have selected yes for them all, hit Process Everything Flagged as Yes. This will loop through all of the files, pulling the data into the Processing tab, then pasting/appending it to right of the data in the DATA tab, like you wanted.

    I created a few sample files to grab sample data from and it processed 100 files in 21 seconds so it should do 300 in about a minute.

    NOTE: you MUST enable macros, you must have the Microsoft ActiveX Data Objects 2.9 Library checked as an available reference.
    To do so use the following: http://msdn.microsoft.com/en-us/libr.../gg264402.aspx
    Thank you so much for your help, I believe this is just what I need. However, I do not have "Microsoft ActiveX Data Objects 2.9 Library". Do you (or anyone else) know where I can download this version?

  5. #5
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    If I run it as is without "Microsoft ActiveX Data Objects 2.9 Library" I get the following error:

    Noname.jpg

    Is this because I am missing Microsoft ActiveX Data Objects 2.9 Library, or something else?

  6. #6
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    UPDATE: I am having errors because I am trying to process pre-2010 files (XLS). This code works great if you it is an XLSX file. Do you have any tips to for this to work in Copy/Paste of XLS files (Multiple) to XLSX (Master WORKBOOK)?

    Thanks

  7. #7
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Copy Columns from Workbook to MasterWorkbook

    Did you activate the reference library as stated above?

  8. #8
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Copy Columns from Workbook to MasterWorkbook

    Yeah, I suppose that would have been good to know, I dont think the ADO works with 97-03 files.
    Last edited by mikeTRON; 01-21-2014 at 01:37 AM.

  9. #9
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  10. #10
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    try this solution.
    Thank you so much. It worked fairly well; however, it only processed the first file and stopped after that. Any idea on how to get it to process the rest of the files?

    Thanks again!

    PS. I left the condition blank. In fact... I am a little confused as to what the condition is used for?
    Last edited by timdecker; 01-21-2014 at 09:26 AM.

  11. #11
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    can you post a screen shot of the my settings tab.

  12. #12
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    can you post a screen shot of the my settings tab.
    Noname.jpg

    For some reason it keeps bringing in Col A and only processing the first file....

  13. #13
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    i guess this was the last updated file can you download the file from the below link:


    http://www.excelforum.com/excel-prog...ml#post3533686

  14. #14
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    i guess this was the last updated file can you download the file from the below link:


    http://www.excelforum.com/excel-prog...ml#post3533686
    That ended up working out pretty well. Thank you for that.

    Is there any way to make it so it starts the copy at Col B and each new file is pasted across horizontally instead of vertically down the worksheet?

    Also, I need it to paste values. It pasted the values for the first workbook but not the second.

    EDIT: Got it to paste values and format, now I just need it to paste horizontally instead of vertically into the worksheet.
    Last edited by timdecker; 01-21-2014 at 12:17 PM.

  15. #15
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    try replacing this line of code to transpose the data

    from :
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.

    to copy the range that you have mentioned

    change this line of code from :
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    try replacing this line of code to transpose the data

    from :
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.

    to copy the range that you have mentioned

    change this line of code from :
    Please Login or Register  to view this content.
    to:
    Please Login or Register  to view this content.
    That still didn't work.

    Here is what my files look like, but much much much longer.

    Noname.jpg

  17. #17
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    can you post 2 of your data file (sample with dummy values if information is sensitive).

    also post a third file with the output required.

  18. #18
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    can you post 2 of your data file (sample with dummy values if information is sensitive).

    also post a third file with the output required.
    Ok here are 2 sample files and what I would like the final file to look like:

    Collection.zip

    Couldn't add atachment via this forum so I used a 3rd party, please let me know if you prefer a different host.

    THANK YOU SO MUCH!!!!

  19. #19
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    try this file and let me know if it works. tested it on the 2 files and it works as desired.
    Attached Files Attached Files

  20. #20
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    try this file and let me know if it works. tested it on the 2 files and it works as desired.
    Wow. THANK YOU SO MUCH! That works just how I wanted it. You have done more than enough and have truly gone out of your way to help me.

    But... =) When you were looking at the files, you saw columns that contained nothing but 0. Any idea on how best to clean that up?

    You don't have to help any more if you don't want as you have truly exceeded my expectations.

    THANK YOU!

  21. #21
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    What we can try to do is the delete all the columns that are starting with 0 on row 5 . Will this logic hold good ?

    I am not gonna sleep till i get this thread solved.

  22. #22
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    What we can try to do is the delete all the columns that are starting with 0 on row 5 . Will this logic hold good ?

    I am not gonna sleep till i get this thread solved.
    That sounds good to me. Logic is good to go.


  23. #23
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    done, let me know if its fine.

    Out of curiosity , i would like to know how many files would be merged in a real life scenario ?

  24. #24
    Registered User
    Join Date
    09-29-2012
    Location
    Dallas, Texas
    MS-Off Ver
    Excel 2010
    Posts
    35

    Re: Copy Columns from Workbook to MasterWorkbook

    Quote Originally Posted by xlbiznes View Post
    done, let me know if its fine.

    Out of curiosity , i would like to know how many files would be merged in a real life scenario ?
    That was perfect! Thank you, again, so very much.

    On my site there are about 350+ files. With all the other sites combined it is something like 1200+.

    If we ran out of room I would just create a 2nd master file. I have to add some more code to it to get it across to our oracle system, but that is a cake walk compared to what you brought to the table.

  25. #25
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Copy Columns from Workbook to MasterWorkbook

    you are welcome, had fun getting this done.

    All the best.

+ 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. Need to Copy Columns from Previous Workbook to Newly Opened Workbook
    By BYizz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-06-2012, 06:33 AM
  2. [SOLVED] copy rows from 42 workbooks into masterworkbook
    By kandre in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-04-2012, 10:08 AM
  3. [SOLVED] COPY from an open workbook with particular sheet and columns to active workbook
    By purin0c0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-12-2012, 03:57 PM
  4. VBA: Automate Copy from Masterworkbook to SeperateWorkbook upon completion of daily inputs
    By NumberCruncher8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-28-2012, 11:46 PM
  5. Copy columns from closed workbook to different columns in open workbook
    By jGLZa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-04-2012, 11:03 PM

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