Save a range to a new workbook and save as a specific title?

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
HI All,

bit of a strange one, i have been researching and cannot find anything relating to this. but i want to save a range in a workbook to a new workbook in a specific location under a new name.

so i have workbook 1 with 4 sheets i want to save sheet 1 range A2:R10000 as a new workbook as "TODAYSDATE"_created. to say "Z:"

is this possible? if so can someone help me with a VBA button?

thank you!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
adapt this to your needs
- 2 suggestions for file name included (use only one or something else!)
- you did not say whether values or formulas to be copied (delete PasteValues to retain formulas)

Code:
Sub SaveRangeToNewBook()
Dim Rng         As Range:       Set Rng = ThisWorkbook.Sheets("[COLOR=#ff0000]Sheet1[/COLOR]").Range("[COLOR=#ff0000]A2:R10000[/COLOR]")
Dim Wb          As Workbook:    Set Wb = Workbooks.Add
Dim fpath       As String:      fpath = "[COLOR=#ff0000]K:\folder\Subfolder[/COLOR]"
Dim fname       As String:      fname = "ConsistentName" & Format(Date, "_YYMMDD")
                                fname = Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1) & Format(Date, "_YYMMDD")
Rng.Copy
With Wb.Sheets(1).Range("A1")
    .PasteSpecial (xlPasteAll)
    .PasteSpecial (xlPasteValues)
    .PasteSpecial (xlPasteColumnWidths)
End With

'save the workbook
Wb.SaveAs Filename:=fpath & Chr(92) & fname, FileFormat:=51
'and close
Wb.Close (False)
End Sub
 
Upvote 0
Thank you so much! works a dream!

i was able to update the line
Code:
[COLOR=#333333]fname = Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1) & Format(Date, "_YYMMDD")[/COLOR]
to
Code:
fname = Left(ThisWorkbook.Name, InStrRev(ThisWorkbook.Name, ".") - 1) & Format(Date, "_DDMMYYYY") & ("_Created")
which capture the desired file name in case you needed this too.

thank you!
 
Upvote 0

Forum statistics

Threads
1,214,592
Messages
6,120,433
Members
448,961
Latest member
nzskater

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