+ Reply to Thread
Results 1 to 6 of 6

Loop through folder, open each file, copy/paste into master worksheet, close each file

  1. #1
    Registered User
    Join Date
    05-01-2022
    Location
    Florida, USA
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Loop through folder, open each file, copy/paste into master worksheet, close each file

    Hi,
    I've recently been figuring out how to automate some of my stuff using macros and now I'm stuck with the last step I need to complete. Currently I have my macro needs broken down into 3 parts (I'm sure I could do all of this in 1 macro, but I'm not that fancy and I'm fine keeping it the way it is). Here's what I have.

    Macro 1: turns raw data file into useable file and saves it.
    Macro 2: loops through a folder to complete Macro 1. (all data files now look identical, but have different workbook names and different worksheet names from each other (only 1 sheet per workbook)).
    Macro 3: loops through same folder to copy data from all files (100+) to master workbook.

    I'm stuck on Macro 3 and can't figure out how to do it. The way I have it right now, Macro 3 is stored in the master workbook. If it should be/is easier to be somewhere else, please let me know!

    The master workbook is a .xlsm file. Each data file is a .csv file.

    I have my master workbook and the sheet that I want all of the copied/pasted data to appear on. This master file is not in the same folder as the files that have the data (the data files are 2 levels deeper in subfolders if that matters). Each file that needs to be copied has data in A1:AP101. I need A2:AP101 copied from each file and pasted in the master worksheet. Each file needs to be pasted on the next available row.

    Attached is a sample file of data.

    Below is the code I have attempted to use from davesexcel:

    Please Login or Register  to view this content.
    What happens when I use this code is basically nothing. I can see Excel working like it's trying to copy/paste the data, but nothing is copied into the master worksheet. The macro is completed without any errors, however, so I'm not sure what's happening or where things are getting lost.

    Any help is appreciated!!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Loop through folder, open each file, copy/paste into master worksheet, close each file

    Edit the line

    Please Login or Register  to view this content.
    to include a '.' before Range
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this !


    Or rather than useless variables just directly copy the range !

    So removing the useless the VBA procedure revamped :
    Please Login or Register  to view this content.
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-01-2022 at 06:53 PM. Reason: optimization …

  4. #4
    Registered User
    Join Date
    05-01-2022
    Location
    Florida, USA
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: Loop through folder, open each file, copy/paste into master worksheet, close each file

    Hi cytop,
    This worked perfectly, thank you so much!!

  5. #5
    Registered User
    Join Date
    05-01-2022
    Location
    Florida, USA
    MS-Off Ver
    Microsoft 365
    Posts
    3

    Re: Hi, try this !

    Quote Originally Posted by Marc L View Post
    [INDENT]
    Or rather than useless variables just directly copy the range !
    This didn't do anything for me, but I'm not sure why. Excel looked like it was working again but nothing pasted into the master worksheet. The suggestion above from cytop did work, so I'm going with that for now. But I'd be happy to try yours again; I just don't have the knowledge to know where it's going wrong.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Loop through folder, open each file, copy/paste into master worksheet, close each file


    As it well works on my side …

    Thanks for the rep' !

+ 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. Replies: 8
    Last Post: 12-02-2019, 03:42 PM
  2. [SOLVED] File dialog box to open a excel file then copy data close file
    By mmikem in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2019, 09:57 AM
  3. Replies: 3
    Last Post: 01-05-2014, 05:50 AM
  4. [SOLVED] Copy/paste Range of worksheets of several files in a folder to a master file
    By mrjinx007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-18-2013, 01:02 PM
  5. Open 2nd file(CSV) from cell reference, copy columns to main file & close 2nd file
    By Langchop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2013, 05:09 AM
  6. [SOLVED] Open specific folder, select file to open and copy then paste
    By Kranky in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-22-2012, 12:14 AM
  7. Replies: 2
    Last Post: 09-11-2012, 09:42 AM

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