Create Folder and Subfolders from the Cell

Atlok

New Member
Joined
Jul 28, 2015
Messages
27
Hello friends,

I am trying to create folders and subfolders from the cells by using VBA code.

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]France[/TD]
[TD]Paris[/TD]
[TD]Nice[/TD]
[TD]Marseille[/TD]
[TD]Lyon[/TD]
[TD]Nantes[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]UK[/TD]
[TD]London[/TD]
[TD]Manchester[/TD]
[TD]Liverpool[/TD]
[TD]Oxford[/TD]
[TD]Preston[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Italy[/TD]
[TD]Milan[/TD]
[TD]Naples[/TD]
[TD]Rome[/TD]
[TD]Turin[/TD]
[TD]Genoa[/TD]
[/TR]
</tbody>[/TABLE]


Please find the code I tried to use below:

Code:
Sub CreateFolderStructure()    For Each objRow In UsedRange.Rows
        strFolders = "C:\Users\USERID\Desktop\newnew"
        For Each ObjCell In objRow.Cells
            strFolders = strFolders & "\" & ObjCell
        Next
        Shell ("cmd /c md " & Chr(34) & strFolders & Chr(34))
    Next
End Sub

When I run the code, the following things created:


  • C:\Users\USERID\Desktop\newnew\France\Paris\Nice\Marseille\Lyon\Nantes
  • C:\Users\USERID\Desktop\newnew\Italy\Milan\Naples\Rome\Turin\Genoa
  • C:\Users\USERID\Desktop\newnew\UK\London\Manchester\Liverpool\Oxford\Preston

Instead of that, I want this thing to happen:


  • C:\Users\USERID\Desktop\newnew\France\Paris
  • C:\Users\USERID\Desktop\newnew\France\Nice
  • C:\Users\USERID\Desktop\newnew\France\Marseille
  • C:\Users\USERID\Desktop\newnew\France\Lyon
  • C:\Users\USERID\Desktop\newnew\France\Nantes
  • C:\Users\USERID\Desktop\newnew\Italy\Milan
  • C:\Users\USERID\Desktop\newnew\Italy\Naples
  • C:\Users\USERID\Desktop\newnew\Italy\Rome
  • C:\Users\USERID\Desktop\newnew\Italy\Turin
  • C:\Users\USERID\Desktop\newnew\Italy\Genoa
  • C:\Users\USERID\Desktop\newnew\UK\London
  • C:\Users\USERID\Desktop\newnew\UK\\Manchester
  • C:\Users\USERID\Desktop\newnew\UK\\Liverpool
  • C:\Users\USERID\Desktop\newnew\UK\\Oxford
  • C:\Users\USERID\Desktop\newnew\UK\\Preston

How can I do that? By the way, if you want to change the whole formula, please feel free to change. I will apply it for more than 250 cells.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
My query is exactly same.
No it isn't. The OP's request is for multiple levels of subfolders (subfolders within subfolders within subfolders, etc with 1 subfolder in each parent folder). Your request is for only 2 levels of subfolder with multiple subfolders in each 1st level subfolder.

In any case, this thread is 6 years old, so please start a new thread.
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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