0% found this document useful (0 votes)
94 views

Creating Folders and Sub-Folders Using Excel VBA - A Step-by-Step

This document provides a code sample for creating folders and subfolders in Excel using VBA. It begins with an introduction to the tutorial and a request for viewers to support the YouTube channel. It then provides the VBA code to create folders based on cell values in a worksheet. It loops through each row to get the main folder name from the first cell and checks if it exists, creating it if not. It then loops through additional cells to get subfolder names, checking if they exist and creating them. At the end it resets the main folder path and loops to the next row.

Uploaded by

Naveed Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Creating Folders and Sub-Folders Using Excel VBA - A Step-by-Step

This document provides a code sample for creating folders and subfolders in Excel using VBA. It begins with an introduction to the tutorial and a request for viewers to support the YouTube channel. It then provides the VBA code to create folders based on cell values in a worksheet. It loops through each row to get the main folder name from the first cell and checks if it exists, creating it if not. It then loops through additional cells to get subfolder names, checking if they exist and creating them. At the end it resets the main folder path and loops to the next row.

Uploaded by

Naveed Ahmed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Log in

Excel 10 Tutorial

3 0 J A N U A RY AT 1 8 : 3 0

Creating Folders and Sub-Folders using Excel VBA: A Step-


by-Step Guide
Thank you so much for being here. Feel free to copy the code below and use it on
your project. Please check the video above for detailed instructions. Thanks for your
time.

You know, it's tough to solve excel problems and create tutorials on it. It takes a lot of
time & effort. Without your support, it becomes more challenging. Please take a
moment and think about it.

If you can, please support the channel, so I can keep this channel running and
provide different solutions for Excel-related problems. Thanks a Million, in advance.
I'm counting on you.

PS. Don't forget to subscribe the channel: http://bit.ly/2GOqj7k

Visit our website for more: msexceltutorial.com

Here goes the Code used in the video:

Sub CreateFolders()

'Created by Excel 10 Tutorial

'For more information Visit: https://msexceltutorial.com

'Declare variables for the main folder and subfolder name

Dim mainFolder As String

Dim subFolder As String

Dim subfolders As Range

'Set the main folder path

mainFolder = ThisWorkbook.Path & "\"

'Loop through each row in the worksheet

For i = 1 To ActiveSheet.UsedRange.Rows.Count

    'Get the main folder name from first cell of the current row

Become a1).Value
    mainFolder = mainFolder & ActiveSheet.Cells(i, patron
Skip navigation
    'Check if the main folder does not exist
Log in
    If Len(Dir(mainFolder, vbDirectory)) = 0 Then

    'Create the main folder

    MkDir mainFolder

    End If

    'Get the range of subfolder names from the rest of the cells in the current row

    Set subfolders = ActiveSheet.Range(ActiveSheet.Cells(i, 2), ActiveSheet.Cells(i,


ActiveSheet.UsedRange.Columns.Count))

    'Loop through the subfolder names

    For Each cell In subfolders

        'Create subfolder name if the cell has value

        If Not IsEmpty(cell) Then

            subFolder = cell.Value

            'Check if the subfolder does not exist

            If Len(Dir(mainFolder & "\" & subFolder, vbDirectory)) = 0 Then

                'Create the subfolder

                MkDir mainFolder & "\" & subFolder

            End If

        End If

    Next cell

    'Reset main folder path

    mainFolder = ThisWorkbook.Path & "\"

Next i

End Sub

Join the conversation...

By becoming a patron, you’ll instantly unlock access to 3 exclusive posts

3
videos

Tiers Become a patron


Skip navigation
$5 Tier Log in
$5 per month

Show more tiers

Recent Posts

How to Make a Cell Editable in Excel Based on Another Cell


15 May at 15:33

How to Create Excel Workbooks Based on A List In Excel


3 April at 18:15

How to Hide Columns Based On Cell Values in Excel


27 March at 18:16

How to Hide Rows Based on Cell Values In Excel


19 March at 19:31

How to Insert Date and Time if a Checkbox is Checked in Excel


27 February at 16:07

How to Create Dynamic Table of Contents in Excel


20 February at 18:15

Language: English (United Kingdom)

Currency: USD

About Help Centre & FAQs

Careers Developers

Create on Patreon App Directory

Brand Blog

Press Patreon U | Creator Coaching

Become a patron
Partners
Skip navigation Community Guidelines

You might also like