Help required

joy_666

Board Regular
Joined
Dec 10, 2008
Messages
121
Hi,

I have the 2 codes as mentioned below

1)

Sub test()
Dim fso As Object, mySir As String, temp As String
Set fso = CreateObject("Scripting.FileSystemObject")
myDir = "E:\test\"
On Error Resume Next
For Each r In Range("a1", Range("a" & Rows.Count).End(xlUp))
Err.Clear
temp = fso.CreateFolder(myDir & r.Value)
If Err = 0 Then

End If
Next
Set fso = Nothing
End Sub

2)

Sub sample()
Dim i As Long, myFolder As String
myFolder = "E:\joy\Week"
For i = 1 To 52
If Dir(myFolder & i, vbDirectory) = "" Then MkDir myFolder & i
Next
End Sub

The first code creates folders based on the values provided in Column A

The second code creates 52 folders of the 52 weeks in a year.

What i want to do is to create 52 folders ( 52 weeks) within each folder from column A

That is to create folder from the Column A and 52 sub folders in it.

Kindly help.
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Greetings Joy,

For this example, I did not use the range of cells for the naming of the parent folders, as I figure you are probably only looking to run this once. Of course you can substitute the range for the array.

In a Standard Module:
Code:
Sub CreateParentFolders()
Dim fso As Object '//IF early bound> As FileSystemObject//
Dim fol_par As Object '//IF early bound> As Folder//
Dim strMyDir As String
Dim aryFolders()
Dim i As Long
Dim lSubFolNum As Long
 
    strMyDir = ThisWorkbook.Path & Application.PathSeparator
    aryFolders = Array("Folder_01", "Folder_02", "Folder_03")
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    For i = LBound(aryFolders()) To UBound(aryFolders())
        Set fol_par = fso.CreateFolder(strMyDir & aryFolders(i))
        
        For lSubFolNum = 1 To 52
            fol_par.SubFolders.Add "Week" & Chr(32) & lSubFolNum
        Next
    Next
End Sub

Hope this helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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