Create Folders & Sub-Folders as per cell of Excel

poonamSS

New Member
Joined
Sep 12, 2021
Messages
9
Office Version
  1. 2013
Platform
  1. Windows
Dear Sir,
This is my excel:
Sr.No.Total Link loanUnique IDLoan_NoLink Loan No. 2Link Loan No. 3Link Loan No. 4
84981482917473991313228655270732989781
104980889798653243712775132902111161743
125244446477143
2193535046431728
3298088238386959
4393550511282887841610014249675
5398167592531911234383713167967
63101769291364074234717676170740
73101778451329260292504683591255
9398993331336142519318804538703


Unique ID is my main Folder - Loan_No, Link Loan No. 2, Link Loan No. 3 & Link Loan No. 2 are subfolders in Unique ID Folder.

I need Path of Folders to be: C:\Users\Admin\Dropbox\poonam\(Insert Unique ID Folder)\(subfolder name)


so Folder “Poonam” will have Folder “9814829” and subfolders “1747399”, “13132286”,”5527073”, “2989781”

the path will be like this
C:\Users\Admin\Dropbox\poonam\9814829\1747399
C:\Users\Admin\Dropbox\poonam\9814829\13132286
C:\Users\Admin\Dropbox\poonam\9814829\5527073
C:\Users\Admin\Dropbox\poonam\9814829\2989781

kindly help me with a VBA for the same at the earliest. Thank you
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this
VBA Code:
Sub CreateFolder()

Dim FPath As String, newDir As String
Dim cell As Range, col As Range, rngFolder As Range, rngCol As Range
Dim ws As Worksheet

Set ws = ActiveWorkbook.Sheets("Sheet1")  ' chage if necessary
Set rngFolder = ws.Range("C2", ws.Cells(Rows.Count, "C").End(xlUp))

FPath = "C:\Users\Admin\Dropbox\poonam\"
For Each cell In rngFolder
    newDir = FPath & cell & "\"
    MkDir newDir
    Set rngCol = ws.Range("D" & cell.Row, ws.Cells(cell.Row, Columns.Count).End(xlToLeft))
    For Each col In rngCol
        MkDir newDir & col
    Next
Next

End Sub
 
Upvote 0
Hi, a VBA demonstration to paste to the top of the worksheet module (for Excel versions prior to 2010 version remove PtrSafe statement) :​
VBA Code:
Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath$) As Boolean

Sub Demo1()
           Const P = "C:\Users\Admin\Dropbox\poonam\"
             Dim V
    With [A1].CurrentRegion.Rows("2:" & [A1].CurrentRegion.Rows.Count).Columns
        For Each V In Evaluate("""" & P & """&" & .Item(3).Address & "&""\""&" & .Item(4).Resize(, .Count - 3).Address)
          If Not V Like "*\" Then MakeSureDirectoryPathExists V & "\"
        Next
    End With
End Sub
 
Upvote 0
Hi, a VBA demonstration to paste to the top of the worksheet module (for Excel versions prior to 2010 version remove PtrSafe statement) :​
VBA Code:
Private Declare PtrSafe Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath$) As Boolean

Sub Demo1()
           Const P = "C:\Users\Admin\Dropbox\poonam\"
             Dim V
    With [A1].CurrentRegion.Rows("2:" & [A1].CurrentRegion.Rows.Count).Columns
        For Each V In Evaluate("""" & P & """&" & .Item(3).Address & "&""\""&" & .Item(4).Resize(, .Count - 3).Address)
          If Not V Like "*\" Then MakeSureDirectoryPathExists V & "\"
        Next
    End With
End Sub

Hello,

I was directed to your thread and it does work wonderfully!

BUT, how can I change your code to start with a cell for example "C2" then put subfolders inside of it from that column in lieu of the row as indicated by the code in reply here?

Please let me know because I know it is NOT:

VBA Code:
  With [A1].CurrentRegion.Column("2:" & [A1].CurrentRegion.Rows.Count).Columns

Thank you!
-Pinaceous
 
Upvote 0
Better to hijack this thread let's continue on your opened thread where I have linked this one​
where you should elaborate and detail your source range or better just attaching a sample via XL2BB or via a files host website …​
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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