Save sheet as a new workbook with date from specific cell

Aviles

Board Regular
Joined
Dec 17, 2008
Messages
163
Hi all,

I have a sheet named "Temp" that I would like to save as a new seperate workbook (xlsx), with the name "Trade Date" together with the specific date from cell C4 of the "Home" sheet (eg: "Trade Date dd/mm/yyyy")

I would like to name the sheet of this new workbook "Dealt" and then for the workbook to be saved in the following directory: S:\Folder1\Folder2\Folder3

I would then like the new workbook to be closed and then return to the original source workbook.

I found this code which I believe is a good start, but I'm not sure how to add the date from cell C4 of Home sheet.

Code:
Sub Copy()

Sheets("Temp").Copy
ActiveWorkbook.SaveAs "Trade Date.xlsx"
ActiveWorkbook.Close

End Sub

Any help would be appreciated.

Thanks,
Ed.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
eg: "Trade Date dd/mm/yyyy"

You cannot put the "/" in a file name, I recommend using the "-"

How about:
VBA Code:
Sub Copy()
  Dim sDate As String, sPath As String
  sPath = "S:\Folder1\Folder2\Folder3\"

  sDate = Format(Sheets("Home").Range("C4").Value, "dd-mm-yyyy")
  Sheets("Temp").Copy
  ActiveSheet.Name = "Dealt"
  ActiveWorkbook.SaveAs sPath & "Trade Date " & sDate & ".xlsx"
  ActiveWorkbook.Close False
End Sub
 
Upvote 0
You cannot put the "/" in a file name, I recommend using the "-"

How about:
VBA Code:
Sub Copy()
  Dim sDate As String, sPath As String
  sPath = "S:\Folder1\Folder2\Folder3\"

  sDate = Format(Sheets("Home").Range("C4").Value, "dd-mm-yyyy")
  Sheets("Temp").Copy
  ActiveSheet.Name = "Dealt"
  ActiveWorkbook.SaveAs sPath & "Trade Date " & sDate & ".xlsx"
  ActiveWorkbook.Close False
End Sub

Hi @DanteAmor

Thanks for the reply. I tried your code and it works well, thank you. I would like to make a couple of amendments if I could please.

How can the code be changed to paste values only to the new workbook?

Also, after I finish with this funtion, I would like to continue with additional code after the 'ActiveWorkbook.Close False' line and before 'End Sub', but it seems like this code ends the Sub before it can get to my other code. Is there a way to amend the code so it does not end the current Sub?

Thanks,
Ed.
 
Upvote 0
How can the code be changed to paste

VBA Code:
Sub Copy()
  Dim sDate As String, sPath As String
  sPath = "S:\Folder1\Folder2\Folder3\"
  sPath = "C:\trabajo\varios\"

  Application.ScreenUpdating = False
  sDate = Format(Sheets("Home").Range("C4").Value, "dd-mm-yyyy")
  Sheets("Temp").Copy
  ActiveSheet.Name = "Dealt"
  ActiveSheet.Cells.Copy
  ActiveSheet.Range("A1").PasteSpecial xlPasteValues
  ActiveWorkbook.SaveAs sPath & "Trade Date " & sDate & ".xlsx"
  ActiveWorkbook.Close False
  Application.ScreenUpdating = True
  '
  'here your code
  '
End Sub

Or put your code here and I adapt it.
 
Upvote 0
VBA Code:
Sub Copy()
  Dim sDate As String, sPath As String
  sPath = "S:\Folder1\Folder2\Folder3\"
  sPath = "C:\trabajo\varios\"

  Application.ScreenUpdating = False
  sDate = Format(Sheets("Home").Range("C4").Value, "dd-mm-yyyy")
  Sheets("Temp").Copy
  ActiveSheet.Name = "Dealt"
  ActiveSheet.Cells.Copy
  ActiveSheet.Range("A1").PasteSpecial xlPasteValues
  ActiveWorkbook.SaveAs sPath & "Trade Date " & sDate & ".xlsx"
  ActiveWorkbook.Close False
  Application.ScreenUpdating = True
  '
  'here your code
  '
End Sub

Or put your code here and I adapt it.

Thank you! That worked great.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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