+ Reply to Thread
Results 1 to 6 of 6

Loop through files in a folder

  1. #1
    Registered User
    Join Date
    03-11-2014
    Location
    Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    37

    Loop through files in a folder

    Hi all

    I would like to create a Macro which does the following task.
    I have a Workbook Master.xlsx with a worksheet "source"
    The path of Master.xlsx is C:\Test
    In the Directory C:\Test\projects i have about 50 files which all contain the String "Forecast" in their filename.
    These Forecast Workbooks need an update in the Worksheet "actuals"

    So, i need a Macro that copies WS "source" from WB "Master" to WS actuals in all WB's Forecast.

    Can you help me, im new with VBA....

    Thanks in advance
    Pascal
    Last edited by paesu57; 03-11-2014 at 10:07 AM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Loop through files in a folder

    It depends on what you mean by "need an update" - this code will copy all the cell on sheet "Source" and paste them over the cells on sheet "Actual" of all the workbooks. I would make a copy of all the "Forecast" files and put them into another folder when you test this.

    Sorry that I did a bad job of editing after pasting the code into my post

    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 03-12-2014 at 09:24 AM. Reason: Cut out an important line from the code after pasting
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    03-11-2014
    Location
    Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Loop through files in a folder

    Hi Bernie
    Thank you! But I have another problem with your code: The files only contain "Forecast" in their name, but that ain't the whole filename. I'm getting the runtime Error "File not found".
    When I directly enter

    Set wkbkF = Workbooks.Open(C:\Test\Projects\Forecast.xlsx"), it works, but loops infinitely and unstoppable ^^ ...


    )

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Loop through files in a folder

    There's a typo and something missing in that code:

    Please Login or Register  to view this content.
    多么想要告诉你 我好喜欢你

  5. #5
    Registered User
    Join Date
    03-11-2014
    Location
    Switzerland
    MS-Off Ver
    Excel 2010
    Posts
    37

    Re: Loop through files in a folder

    Thank you genious

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Loop through files in a folder

    Thanks for catching my bad editing job...

+ 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. Loop through all files in folder
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2013, 09:40 PM
  2. VBA Loop for a folder of all the files, Loop all the worksheet in each workbook
    By nanjingwoodworking in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-07-2013, 07:20 PM
  3. Loop between 2 files in a folder
    By jharaldson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2013, 02:33 AM
  4. loop through all files in a folder except for one of them
    By masben in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-19-2013, 10:23 AM
  5. Loop through files in a folder
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-28-2010, 06: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