I would like to use an entire column as my range for my code, but I keep running to Type Mismatch error, This is my Code.
Dim xRgDate As Range
Dim xCellDate As Range
Set xRgDate = Range("E:E")
For Each xCellDate In xRgDate
If Not IsEmpty(xCellDate) Then
xMonth = Month(xCellDate.Value)
xMonthName = MonthName(xMonth)
If Len(Dir((FPath & "\" & ws.Name & "\" & xMonthName), vbDirectory)) = 0 Then
MkDir (FPath & "\" & ws.Name & "\" & xMonthName)
End If
End If
Next xCellDate
I keep trying to change the Range Selection, for example this works but it's not the entire column
Set xRgDate = Range("E9:E40")
This is the full code
Sub SplitEachMonthToSubFodlers()
Dim FPath As String
FPath = Application.ActiveWorkbook.Path
For Each ws In ThisWorkbook.Sheets
If Len(Dir((FPath & "\" & ws.Name), vbDirectory)) = 0 Then
MkDir (FPath & "\" & ws.Name)
Dim xRgDate As Range
Dim xCellDate As Range
Set xRgDate = ws.Range("E9:E40")
For Each xCellDate In xRgDate
If Not IsEmpty(xCellDate) Then
xMonth = Month(xCellDate.Value)
xMonthName = MonthName(xMonth)
If Len(Dir((FPath & "\" & ws.Name & "\" & xMonthName), vbDirectory)) = 0 Then
MkDir (FPath & "\" & ws.Name & "\" & xMonthName)
End If
End If
Next xCellDate
Else
MsgBox ("Folders Already Existed")
End If
Next ws
MsgBox ("Folders Created")
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Create Monthly Subfolders