hkydad
Board Regular
- Joined
- May 16, 2013
- Messages
- 66
- Office Version
- 365
- Platform
- Windows
I have the code below but when I run the code, the folders on my active worksheet are not being created and I'm not sure why.
The folder names I want to create are below and are all in column A beginning with row 1. Any assistance would be greatly appreciated.
01-2024
02-2024
03-2024
Private Sub CreateFolder()
Dim xdir As String
Dim fso
Dim fsoSub
Dim lstrow As Long
Dim i As Long
Dim xdirsubfolder As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoSub = CreateObject("Scripting.FileSystemObject")
lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = True
For i = 1 To lstrow
xdir = "J:\_Dvision\Group\Tim\2024\" & Range("A" & i).Value
xdirsubfolder = "J:\_Division\Group\Tim\2024\" & Range("A" & i).Value & "\" & Range("A" & i).Offset(0, 3)
If Not fso.FolderExists(xdir) Then
fso.CreateFolder (xdir)
End If
If Not fsoSub.FolderExists(xdirsubfolder) Then
fsoSub.CreateFolder (xdirsubfolder)
End If
Next
Application.ScreenUpdating = True
End Sub
The folder names I want to create are below and are all in column A beginning with row 1. Any assistance would be greatly appreciated.
01-2024
02-2024
03-2024
Private Sub CreateFolder()
Dim xdir As String
Dim fso
Dim fsoSub
Dim lstrow As Long
Dim i As Long
Dim xdirsubfolder As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoSub = CreateObject("Scripting.FileSystemObject")
lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = True
For i = 1 To lstrow
xdir = "J:\_Dvision\Group\Tim\2024\" & Range("A" & i).Value
xdirsubfolder = "J:\_Division\Group\Tim\2024\" & Range("A" & i).Value & "\" & Range("A" & i).Offset(0, 3)
If Not fso.FolderExists(xdir) Then
fso.CreateFolder (xdir)
End If
If Not fsoSub.FolderExists(xdirsubfolder) Then
fsoSub.CreateFolder (xdirsubfolder)
End If
Next
Application.ScreenUpdating = True
End Sub