+ Reply to Thread
Results 1 to 13 of 13

VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not working

  1. #1
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not working

    Hi all,

    Here's the scenario. In a directory I have 200 or so xlsm files, all of which contain a sheet called "Results". I have a "masterlog" workbook also with a sheet called "log" which is to contain all the data in the "results" sheets of the other workbooks.

    I've obtained a macro to loop through all the xlsm files, copy the data and paste to the Log worksheet. However what I'm finding is that it is copying the same libe over and over again.

    The code below is not by any means ideal and is written this way in an atempt to find where the problem was occuring but I can't seem to find it.

    Any help on this much appreciated - my boss is giving me the evils.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    I did correct a couple of places, but the Dir is the function responsible for getting the next file. I'm not sure if I helped.
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    It works!!!!

    Thank you - this has been driving me nuts for 3 days now!

  4. #4
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Actually - possibly spoke too soon. It is at least copying over the data, but it seems to be looping repeatedly between two different files (so copying data from files A, B, A B etc).

    Any suggestions on what may be causing this? There are about 200 xlsm files in the folder but it's not picking them up.
    Last edited by wonderdunder; 02-10-2014 at 09:27 AM. Reason: Being more specific as to problem

  5. #5
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Maybe right here. Remove the preceding backslash.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Thought that might be the case and removed it but it does the same. I've checked the directory and the files are there and of the correct extension (there are other Excel files as well as documents, pdfs etc in there but don't know if / how / why that would have any effect).

  7. #7
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Add a debug message to watch for filenames.

    Please Login or Register  to view this content.
    Make sure you have the immediate window open Ctrl-G

    Press F8 to step through the code. Watch the window and see what filenames are being generated.

  8. #8
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    I must be a second or two behind your brainwaves....

    Have created a list on another sheet and it is looping through different files - its just copying the original data over and over again.

    Ive checked the data in the files im copying from in case and it is as it should be.

    At least I know the looping bit works!

  9. #9
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Well....
    With the mouse hovered over the line below I get an automation error (wkbSource.Sheets("Results") = <Automation error>.
    Please Login or Register  to view this content.
    Could that have something to do with it?

  10. #10
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Please Login or Register  to view this content.
    This should be just
    Please Login or Register  to view this content.
    (Ha! We're doing it again.)
    Last edited by Tinbendr; 02-10-2014 at 11:25 AM.

  11. #11
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Tried those changes but not making any difference.

    What is weird is that, though the debug shows that different files are being opened, and the list shows the same, I watched the task bar and caught the name of the file - it is opening the same file over and over again, even if the VBA says otherwise.

    I've looked over similar codes elsewhere on line and everything seems in order but I'm getting text blind at the moment. I'll have a breather and try again.

  12. #12
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    <slaps forehead> Forest for the trees, forest for the trees.

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    02-08-2006
    Location
    UK
    MS-Off Ver
    2013
    Posts
    204

    Re: VBA to combine results from multiple workbooks to one spreadsheet - loop/copy not work

    Oh I could kiss you right now but I've got a coldsore!

    Should have known that after my last post.

    Many many thanks again for your efforts in this.

+ 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. [SOLVED] code not working, possibly combine for better results?
    By Russ Fuquay in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-24-2013, 10:42 AM
  2. find copy paste loop multiple results
    By MTB1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-19-2012, 10:53 AM
  3. Copy / Paste multiple loop results in specific column ranges on one worksheet
    By bfbisso in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-24-2012, 01:11 PM
  4. Replies: 7
    Last Post: 02-12-2010, 08:23 PM
  5. loop to copy data from multiple workbooks into one
    By staffordalex in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-05-2008, 01:13 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