Excel VBA: create folder based on column

Luis Diaz
Luis Diaz used Ask the Experts™
Hello experts,

I would like to create a procedure to create multiple folders based on path reported in column A.
If folder cannot be created skip cell and continue to next one.

I have initiate the first part.
Could someone help me to finish the rest of the procedure and add the error conditions?
I attached example file.

Thank you very much for your help.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Excel & VBA Expert
Most Valuable Expert 2018
Awarded 2015
You may try something like this...

Sub Create_Folders()
Dim fso As Object
Dim ws As Worksheet
Dim lr As Long, i As Long
Dim FolderPath As String

Set ws = ActiveSheet
Set fso = CreateObject("Scripting.FileSystemObject")
lr = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = 2 To lr
        FolderPath = ws.Cells(i, "A").Value
        If FolderPath <> "" Then
            If Not fso.FolderExists(FolderPath) Then    'If folder doesn't exists, create it else skip creating the folder
                MkDir ws.Cells(i, "A").Value
            End If
        End If
    Next i
End Sub

Open in new window

Luis DiazIT consultant


Thank you. I will test it soon.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial