Creating a file using a macro - Already have code for the file creation just want to define the code to select certain ranges

Luke1690

Board Regular
Joined
Jul 26, 2022
Messages
121
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How can i get this to work so it finds the last data input in column $m2 and names the file from that range.
If you want to get the value from the last populated cell in column M, you can use:
VBA Code:
strName = Cells(Rows.Count, "M").End(xlUp).Value
 
Upvote 0
Solution
If you want to get the value from the last populated cell in column M, you can use:
VBA Code:
strName = Cells(Rows.Count, "M").End(xlUp).Value
Thanks, i knew it was something simple, just can never remember them.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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