Excel VBA: Loop Through All Files in a Folder

preview_player
Показать описание

Like this tip? Sign up for the Excel VBA course:

VISIT COMPUTERGAGA FOR LOTS MORE TIPS

CONNECT WITH US!
Рекомендации по теме
Комментарии
Автор

I have been searching for this code and it worked like a charm. Saved a lot of times for repeating steps. Thanks so much!

jadenguyen
Автор

clean, simple, efficient, explained. Exactly what I wanted to know with the coded I needed easily available. Kudos to you for being one of the few able to pull off this seemingly remarkable feat of youtube!

aexwor
Автор

What a fantastic tutorial. Just wanted to say thanks so much for all of your videos. This is the second VBA tutorial I've ran into from you and it's been so much help. Cheers!

RoyalsRP
Автор

Thanks for this! I have been trying to find this code explained for a while. Beastly!!!

cantyoufeelthelove
Автор

Great tutorial you explained each line of code which makes it that much easier To use this code. Thank

blackrock
Автор

Excellent macro just tested today works perfectly. I've seen complicated implementations on Google this is by far the easiest way to use the macro.

jayeshsuthar
Автор

Hey Thank you very much, I have been searing for loop through all files. After I watched your video, the macro works very well for my work. Thank you again and have a good day.

bettyna
Автор

We are in 2022 and this macro still works fine. Thanks.

Alhusam
Автор

Excellent. You saved my day at work.

hichamalioui
Автор

Worked! I was using a different script I found online somewhere that had a similar design but was more complicated. It kept erroring out. This one took me about 5 minutes to get to work. Thanks!

personalaccount
Автор

this is beautiful! I had been struggling to accomplish this

HectorPerez-xuks
Автор

Looks good. Pretty sure this solution will need my requirement. Thanks for posting

stephenwilliams
Автор

hey absolutely amazing, you have saved me some time. I have a question, I have written a similar code where I can loop through a folder like you have shown but I need it to populate another excel using the data and then I'd need the output copied into a master folder. I have tried but I recieved an error a system error code &800401AB. Do you have any ideas?

danridge
Автор

Thank you. I was trying to find a way to refine my script. I don't know how to save and close files in a folder. Can I know how to achieve in this script to only run Excel files in a folder? I found if there are other format files such as zip files, the code will run error. Thank you.

sinogarcon
Автор

Thank you! You sir, are brilliant bloke!

diegomazzone
Автор

Ok, having posted below last night, I have now come in to work to use this and hit a few snags in the code.

this seems mostly to be an issue with keyboard input (so not sure who this will affect, but its an easy fix).
1) go through and find all places where the two quote type symbols are used. those being single quote ' and double ". for me, these came in wrong so the macro file didnt recognise them. ***CODE WILL NOT WORK WITHOUT THIS***
the most important areas for this are line 31 and 39 as these double quotes pick up the files.
if you dont change the single quote ' labels for the notes he's made - it will bug the line it is on so stop the dim commands working
also in his code online the bit that selects the cell doesnt work. change the "A1" to make sure you can see it working
2) go through the code online and make sure all your code has matching indents - this is kind of just a cosmetic thing


copy your own code in
profit.



*EDIT*
my code works fine on its own, the test code to make a single cell value change to 60 works, putting my code in in place of that single line and it goes very, very wrong.

*2nd EDIT*
problem in first edit fixed
problem: i had no sheet reference in my code, so each new line was putting code into cell A1 as this was the only one it could find. when used on a single workbook, it defaulted to using only the active worksheet no problems, hence why i didnt know this was an issue.
Solution: copy code into notepad. Edit -> Replace All -> Range(" with Sheets(1).Range("
this works regardless of sheet name and allows the code to properly select the cells to input each formula properly.


*3rd EDIT*
Function for inserting a graph now does not work

*4th EDIT*
edit three is due to the fact files are in .csv format, graphs and bold text will not be retained when saved as .csv. I now need to find a way to change the file format to .xlsx to keep graph when saved.

aexwor
Автор

This information is still very good to use. thanks.

mcannas
Автор

This looks like I will get it working, the macro is running through without any errors but it doesn't seem to be seeing the .csv file within the Dir(MyFolder). Is there something I should be doing to ensure csv files are picked up?

sryan
Автор

This code is awesome. thanks for sharing.

jimbogacz
Автор

I want to be able update a directory of identical template files with different names so they all have the same template model in them. Basically I want to save the master under all the individual files in the directory to make it easier to roll any template changes by macro? Can I use something similar for that? I cant copy the master template in because they're protected from overwrite. Ideas?

seracleroc