VBA to copy current sheet (template) and make one sheet for each day of the month

Jnb99

Board Regular
Joined
Mar 29, 2016
Messages
84
Hi,

The title says it all. I want to use a macro to copy the current sheet(template) to a new sheet complete with the values I've put on the sheet, and the name of the sheet to be renamed to the current date. There is previous threads but not what I need.

Thanks!
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Something like:

Code:
For Each sh In ThisWorkbook.Sheets
    If sh.Name = Format(Date, "dd-mm-yy") Then
        Exit Sub
    End If
Next
Sheets("Template").Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = Format(Date, "dd-mm-yy")
 
Upvote 0


Thank you, this worked 100%!

Now I want to clear the template sheet when I click on the save button I assigned the macro to. I used:

Code:
Sub copysheetandnamedate()myname = Format(Date, "dd-mm-yy")
ActiveSheet.Copy After:=ActiveSheet
ActiveSheet.Name = myname
ActiveSheet.Range("C6:G55").ClearContents
End Sub

But the new sheet it creates is cleared and not my template, what am I doing wrong?
 
Upvote 0
Thanks a lot guys, I got it to work. I used:

Code:
Sub copysheet()Dim WS As Worksheet
Set WS1 = Worksheets("StockTakeTemplate")
ActiveSheet.Copy After:=ActiveSheet
ActiveSheet.Name = Format(Date, "mm-dd-yyyy")
WS1.Range("C6:G55").ClearContents
End Sub

Does anyone have something better?
 
Upvote 0
Thats pretty close to what i gave you. However i would use mine not yours and adapt it to suit your sheet name. Yours has issues. It would fail should it be run twice on the same day. It will also not do what you expect should you run it when any sheet other than stocktaketemplate is the active sheet.
 
Upvote 0
I think I am doing something wrong, because it run an error with your code?

Is there a way to protect the new sheet when you save?
 
Upvote 0
I think I am doing something wrong, because it run an error with your code?

Is there a way to protect the new sheet when you save?

What is the error message and what line of code?
Is the sheet you are copying named "Template" ?
 
Upvote 0
The error is: Compile error, Invalid outside procedure.
The sheet name is "StockTakeTemplate"
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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