Loop through folders and execute code if folder name matches specified names

Status
Not open for further replies.

hopeful_positive

New Member
Joined
Jan 20, 2018
Messages
6
Hello all,

I am new to VBA coding. I had taken a programming course almost 6 years ago and never touched it since but I would like to start learning slowly to automate a lot of my excel stuff.


I am looking for help to code the following the scenario:

I have 10 folders in a particular location on the drive. Out of the 10, there 7 which are named Item 1, Item 2, Item 3, Item 4, Item 5, Item 6 and Item 7. The remaining three are not to be worried about.

I am hoping to code in VBA such that the code would loop through all the folders and if the folder name matches - Item 1, Item 2, Item 3, Item 4, Item 5, Item 6 and Item 7 - execute code A for folders Item 1, Item 2, Item 3 and then execute code B for Item 4, Item 5, Item 6 and Item 7.

Requesting your kindest help.

Thank you !
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
which bit do you want help with?

you'll find most of what you need via google. i just googled with input copied straight from your question

googling for "VBA such that the code would loop through all the folders" finds, amongst others,
https://exceloffthegrid.com/vba-code...r-sub-folders/
https://www.quora.com/How-do-I-loop-...soft-excel-vba

After that you might google for info on a 'select case' statement. Or even a simple IF statement, just to get started.
I googled for "VBA do different things based on value" and found
https://powerspreadsheets.com/excel-vba-tutorial-essential-terms/
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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