Hi Guys,
I found the code below either from you guys or YouTube. i have used it on a few of my workbooks it creates a sub folder with a title from a range . Comes in real handy for my line of work.
So far whenever I've used it I create multiple modules changing the range every time and a button click for each row to activate it.
How can i get this to work so it finds the last data input in column $m2 and names the file from that range.
so only having the use the code once?
As always Thanks in advance guys.
Sub Copy_Foldera23()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim strName As String
Dim WeekStr1 As String
Dim WeekStr2 As String
FromPath = "" '<< Change
ToPath = "-"
Application.CutCopyMode = True
strName = Range("a23")
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath & strName, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath & strName
end sub
I found the code below either from you guys or YouTube. i have used it on a few of my workbooks it creates a sub folder with a title from a range . Comes in real handy for my line of work.
So far whenever I've used it I create multiple modules changing the range every time and a button click for each row to activate it.
How can i get this to work so it finds the last data input in column $m2 and names the file from that range.
so only having the use the code once?
As always Thanks in advance guys.
Sub Copy_Foldera23()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim strName As String
Dim WeekStr1 As String
Dim WeekStr2 As String
FromPath = "" '<< Change
ToPath = "-"
Application.CutCopyMode = True
strName = Range("a23")
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath & strName, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath & strName
end sub