Creating Folders in Other Folders based on Cell Values

mikey2322

Board Regular
Joined
May 10, 2006
Messages
59
Hi All,

I have a directory on my computer C:\Test\ with 10 or more folders in it. I have the folder names in Column A (for example Test1 - Test10) of a spreadsheet name Folder Factor.xls.

I would like some VBA code to go down the rows and find the folder in the C:\Test\ directory based on the folder name in Column A and create another folder within it based on a new folder name in Column B (for example TestA - TestJ). i.e. the directory tree for the first record would look like C:\Test\Test1\TestA\

Any help would be greatly appreciated!

Cheers,

Mike
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Possibly

Code:
Sub MakeFolders()
Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
    MkDir "C:\Test" & "\" & Range("A" & i).Value & "\" & Range("B" & i).Value
Next i
End Sub
 
Upvote 0
Hi,

Lookup the createfolder method.


Dim FSO as Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim MyPath as String
MyPath = "c:\temp\myfolder\"

FSO.CreateFolder MyPath

nigh night
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,919
Members
452,949
Latest member
beartooth91

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