Merge Multiple Ranges of Data

  • Hi,


    I’m after some assistance creating the correct VBA to do the following:


    -I have 14 workbooks all contained within the same folder.
    -The folders path will be “C:\Users\cowen\Documents\Yield Tracker V2”
    -Within these workbooks is a data entry sheet which is sheet fall but named, “DBEntry”
    -The layout of these sheets and the headers are exactly the same for all 14 sites which each have 1 workbook.
    I want to be able to copy across the data from the DB entry sheet, this will always be between column B and s however depending on the amount of data entered it may be 20 rows or it may be 200 rows. Once copied I was the information deposited into an Workbook called Yield Tracker V2 Master and within that sheet DB Entry.
    I would like all the data to merge rather than each workbook over-right the previous one.


    Any help is greatly appreciated Colin

  • Copy/paste this macro into a regular module in your

    [SIZE=13px]Yield Tracker V2 Master workbook and run it from there. The macro assumes that your source files all have an "xlsx" extension and that they are the only files in your folder.[/SIZE]


    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Hi Mumps,


    Thank you for the quick reply,


    I've tried this and it gives a run time error 9 Subscript out of range.


    The line of code highlighted is, Set wsDest = ThisWorkbook.Sheets("DBEntry")


    Just another FYI the source files are macro enabled so am I correct in changing the extension in the VBA code to .xlsm.


    Thanks


    Colin

  • Hi Jolivanes,


    Thanks, for this, I have an nasty habit of inconsistency which I had carried over the master sheet. I've rectified this and it's working which is amazing Thank You.


    However a couple of bits I've noticed:


    -I'm Testing it with 2 sheets currently and the last sheet that is opened and copied is the only data on the destination sheet in the master workbook.


    -Also the data is bring dropped in Cell A3 which included the header row. How would I make it so only the entered data is copied across, this is located in cell B3 on the worksheets.


    Thanks


    Colin

  • Hi,


    Further update on this, it turned out the cells aren't overwriting but rather it's copying all 40,000 rows over rather than just the rows which contain data.


    Thanks


    Colin

  • Is it now working the way you want it? If not, please explain how it is not working.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • It's copying over all the rows on the data inputting sheet regardless of if they have completed data in them. Also the data is being dropped in with headers, the headers are on row 2 the data begins row 3.

  • It would be easier to help if you could post a copy of your

    [SIZE=13px]Yield Tracker V2 Master workbook and a copy of at least one of your source workbooks. You can de-sensitize the data if necessary.[/SIZE]

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Try:

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Amazing, just 2 issues I can see.


    The first is when there are two sheets it seems to cut off the last row of data on the second file copied across, the second is how would I get the starting depositing position to be B:2 instead of A:1


    Great job BTW


    Colin

  • Can you post a copy of that second file where the last row is cut off?

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Is it necessary to have 40000 rows in the "Store" workbooks?

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Hi,


    No necessarily but I think across a quarter we will collect around 15,000 lines of data depending on how many blank rows it leaves.


    Thanks

  • Click here for your files. You will see 2 macros in Module1 of the Master. I was trying two different methods to see which would be faster. Unfortunately, they both seem to take about the same amount of time. You can try both and see what you observe. I have deleted about 25000 empty rows from each of the two "Store" files. They now have 15000 rows. This speeds things up a bit compared to the original files that had 40000 rows. The more empty rows you can delete from the source files, the faster the macro will run. Give them a try.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

  • Hi..


    Here's another that works on your sample (although you MUST remove the text "End" that was in row 15000 (the black row) on each of you DBEntry sheets.. not sure why that was there.. and it makes it hard to find the last used row of data..


    The idea below is to read each Workbook once, add data to Collection and build array, then dump array to sheet.. so as little sheet interactions as possible.


    I haven't played with Collections much at all, but found Pikes thread on it valuable.. https://www.ozgrid.com/forum/f…excel-vba-collection-sort


    It seems you can't dump a Collection straight to sheet( like you would an array)so that's why the extra step of building the array from the Collection is needed..


  • This version should work and is much faster. You don't have to remove the "END" row.

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!