+ Reply to Thread
Results 1 to 3 of 3

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

  1. #1
    Registered User
    Join Date
    01-20-2018
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    10

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

    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 !

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,616

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

    Based only on this details you gave in the post, such approach:

    Please Login or Register  to view this content.
    shall do
    Best Regards,

    Kaper

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

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

    Try this - Change first parameter (path) as required, and change second parameter to TRUE to include all subfolders.

    Replace Debug.Print statements with the actions you wish to take.

    Please Login or Register  to view this content.
    Last edited by Olly; 04-20-2018 at 05:04 AM. Reason: Unnecessary line deleted
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

+ 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 through folders and only implement code if folder name matches from specified names
    By hopeful_positive in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2018, 11:46 AM
  2. [SOLVED] VBA to loop through a folder and all sub folders opening excel files.
    By Lsxtrkiller in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2017, 06:18 PM
  3. Code to loop through workbooks in folder with specific names
    By stephme55 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-31-2016, 07:31 PM
  4. [SOLVED] Search for file names in main folder and its sub folders
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 11-09-2015, 01:17 AM
  5. Create FOLDER in subfoldesr and move folders with specific names into FOLDER
    By Amarjeet Singh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-25-2015, 09:46 AM
  6. Loop Through all Folders - *Ignore Folder Shortcuts*
    By R_S_6 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2013, 05:53 AM
  7. [SOLVED] Renaming Folders in a macro but so far all I can do is loop thru the folder.
    By jody1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2013, 02:22 AM

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