+ Reply to Thread
Results 1 to 2 of 2

VBA Code won't loop through all files in the folder

  1. #1
    Registered User
    Join Date
    03-22-2019
    Location
    Wales
    MS-Off Ver
    2013
    Posts
    1

    VBA Code won't loop through all files in the folder

    I have a bunch of CSV files in one folder. The aim is to copy all the data (excluding the header row) from each file and collate them into one. Below is the code I'm currently using, the problem is the code only copies data from one file then ends completely ignoring all other files in the folder

    Please Login or Register  to view this content.
    I believe that the problematic line is:

    Please Login or Register  to view this content.
    I've come to this conclusion because belovw is the code that us to be in use and my code would loop through very folder. Though since making this change it no longer does.

    Please Login or Register  to view this content.
    The reason I changed the working code is because I no longer required only certain columns, but instead I need all columns to be copied into the file.

    I don't understand why the range change has stopped my program from working as expected . A solution and explanation (if possible) would be much appreciated.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Code won't loop through all files in the folder

    Hi,

    You need to reset the counter to zero for every new file and change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    However, assuming the rows in the range A1:AA1 in the file being copied are contiguous and to avoid the need for the loop you could simplify this to

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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 Code to extract information from all files in a folder to a mastersheet
    By flaire14 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-22-2017, 08:34 PM
  2. Replies: 0
    Last Post: 05-24-2016, 12:32 PM
  3. [SOLVED] Choose a folder and loop through all files in the chosen folder
    By smartbuyer in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2016, 11:19 PM
  4. [SOLVED] Loop Through Folder, Create Emails with Sub Folder Names in Subject, Attach files in sub
    By Rschwar23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-30-2015, 10:06 AM
  5. loop through all files in a folder and run code to unmerge and shift
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-05-2015, 05:02 PM
  6. code to loop through all .docx files in folder
    By rs1aj in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-12-2015, 04:41 PM
  7. Replies: 12
    Last Post: 03-09-2015, 05:52 PM

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