Hello friends,
I am trying to create folders and subfolders from the cells by using VBA code.
<tbody>
</tbody>
Please find the code I tried to use below:
When I run the code, the following things created:
Instead of that, I want this thing to happen:
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.
I am trying to create folders and subfolders from the cells by using VBA code.
A | B | C | D | E | F | |
1 | France | Paris | Nice | Marseille | Lyon | Nantes |
2 | UK | London | Manchester | Liverpool | Oxford | Preston |
3 | Italy | Milan | Naples | Rome | Turin | Genoa |
<tbody>
</tbody>
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.