Trying to form a loop to open up files in other folders

cmarlman

New Member
Joined
Jun 17, 2019
Messages
2
Hi,

I am new to Excel VBA and am still on the learning curve, hopefully one of you can help!

I am trying to form a loop that will run through a list of excel files that I have hard coded in column C. They need to open up one at a time, run the macro in that file, copy data on one of the sheets, paste it in my master workbook, close out, and then open up the next and do the same thing. The files are all in separate folders as well which makes it tougher. Also I plan on adding new file names to column C in the future.

The part I am really struggling to get my head around is how I can open up the excel files that I have hard coded in column C one at a time. Once I can pull them up I'm sure I can figure out the rest.

I have done some extensive googling but there is not much on this type of loop, from what I have found.

Thanks!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I would walk through the range.?

Something like below. Where I have Debug.Print you would put the rest of the code for your process.
This is just to show one method.

Don't forget. the macro recorder can generate a lot of code to help you as well.

HTH
Code:
Sub TestRng()
Dim rngFiles As Range, rng As Range


Set rngFiles = Range("D2:D5")
For Each rng In rngFiles
    Debug.Print rng.Value
Next


Set rng = Nothing
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,052
Members
448,940
Latest member
mdusw

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