Auto Folder Creation based on given path/folder names

harinsh

Active Member
Joined
Feb 7, 2012
Messages
273
Hello Team,
I am looking for the below help in the creation of automation in folder create and assign the names based on the given names in cells/path.

Capture.JPG


If you see column B and C and it goes on till 10 or so on ....when I run the auto program should create the main folder/subfolders accordingly and incase if given path folder exist no need to create again.

Can anyone help with this requirement?
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Sample code for you to test
- validity of folder name is not verified

Amend path to MF1, MF2 etc
fPath = "C:\Folder\subfolder"
Amend worksheet name
Set ws = Sheets("XXX")
VBA Code:
Sub CreateFolders()
    Dim fPath As String, p As String, p2 As String, rng As Range, cel As Range, ws As Worksheet, c As Long
    fPath = "C:\Folder\subfolder"
    Set ws = Sheets("XXX")
    Set rng = ws.Range("A4", ws.Range("A" & ws.Rows.Count).End(xlUp))
    On Error Resume Next
    For Each cel In rng
        p = fPath & "\" & cel
        If cel <> "" Then
            MkDir p
            For c = 1 To 50
                p2 = p & "\" & cel.Offset(, c)
                If Not p2 = p & "\" Then MkDir p2
            Next c
        End If
    Next cel
    On Error GoTo 0
End Sub

If you cannot make it work, post the amended code you are using and the actual worksheet range - and I will try to help resolve any issues
 
Last edited:
Upvote 0
Sample code for you to test
- validity of folder name is not verified

Amend path to MF1, MF2 etc
fPath = "C:\Folder\subfolder"
Amend worksheet name
Set ws = Sheets("XXX")
VBA Code:
Sub CreateFolders()
    Dim fPath As String, p As String, p2 As String, rng As Range, cel As Range, ws As Worksheet, c As Long
    fPath = "C:\Folder\subfolder"
    Set ws = Sheets("XXX")
    Set rng = ws.Range("A4", ws.Range("A" & ws.Rows.Count).End(xlUp))
    On Error Resume Next
    For Each cel In rng
        p = fPath & "\" & cel
        If cel <> "" Then
            MkDir p
            For c = 1 To 50
                p2 = p & "\" & cel.Offset(, c)
                If Not p2 = p & "\" Then MkDir p2
            Next c
        End If
    Next cel
    On Error GoTo 0
End Sub

If you cannot make it work, post the amended code you are using and the actual worksheet range - and I will try to help resolve any issues
Thank you very much ..it's working super....
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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