Looping through each file in two different folders and extracting data to a new workbook

Todor Penchev

New Member
Joined
Aug 1, 2017
Messages
1
Hello everyone,

I am very new to VBA (I have used it for some minor tasks), but at the moment I am faced with a challenge and I am not sure how to approach it.
The task is as follows:

1). I have two folders (two different locations) which contain a number of .csv files (200+)

2). What I need to do is to loop through each file in each of the two folders, extract a single row of data from each of the files to a new workbook, which will contain the macro, where the row titles is for example “Lemons” in one of the files and “Lemon_s” in the other file, and compare the two rows.

3). A potential problem I though of is how I can know which files to match (ie knowing which two files out of 200 in each folder to compare). Potentially I though I could use some common word in both of the file names e.g. one pair of files is called “Lemons_Belgium” and “Lemon_s_Belgium” another pair would be "Lemons_Austria" and "Lemon_s_Austria" - so I could use the common word in each of the files. However, I am not sure how I could do any of the things
outlined above.

Any help will be greatly appreciated.

Thank you very much in advance for your time.

Best,
T
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top