create multiple sheets with new date for each sheet

RandyD123

Active Member
Joined
Dec 4, 2013
Messages
296
Office Version
  1. 2016
Platform
  1. Windows
So far I have this to create sheets:
Code:
Sub SheetCopier()
   Dim x As Integer
   
   x = InputBox("Enter number of times to copy default sheet")
   For numtimes = 1 To x
      'Loop by using x as the index number to make x number copies.
      ActiveWorkbook.Sheets("Default").Copy _
         Before:=ActiveWorkbook.Sheets("Default")
         'Put copies in Before Default Sheet.
   Next
End Sub

So when I run that it lets me decide how many copies of the "Default" sheet I want. However I would like to also have the option to name those sheets I create with a date for each new sheet made (Nov 17 2017) or (111717) using a starting date of my choosing and having each sheet advance 1 day with the new name. (Nov 17 2017), (Nov 18 2017),.......

Also what I have now, if I cancel it, it errors out.

Thank you in advance if anyone can help.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
How about
Code:
Sub SheetCopier()
   Dim x As Long
   Dim NumTimes As Long
   Dim Dt As Date
   
   Dt = InputBox("Please enter a date")
   x = InputBox("Enter number of times to copy default sheet")
   
   For NumTimes = 1 To x
      'Loop by using x as the index number to make x number copies.
      ActiveWorkbook.Sheets("Exist").Copy _
         Before:=ActiveWorkbook.Sheets("Exist")
    ActiveSheet.Name = Format(Dt + NumTimes - 1, "mmm-dd-yyyy")
         'Put copies in Before Default Sheet.
   Next
End Sub
 
Upvote 0
How about
Code:
Sub SheetCopier()
   Dim x As Long
   Dim NumTimes As Long
   Dim Dt As Date
   
   Dt = InputBox("Please enter a date")
   x = InputBox("Enter number of times to copy default sheet")
   
   For NumTimes = 1 To x
      'Loop by using x as the index number to make x number copies.
      ActiveWorkbook.Sheets("Exist").Copy _
         Before:=ActiveWorkbook.Sheets("Exist")
    ActiveSheet.Name = Format(Dt + NumTimes - 1, "mmm-dd-yyyy")
         'Put copies in Before Default Sheet.
   Next
End Sub

I get "subscript out of range" error. Disregard, I had to the sheet name!! work perfectly!!! Thank You!!@
 
Last edited:
Upvote 0
Apologies, i forgot to change the sheet names after testing.
You'll need to change them back
 
Last edited:
Upvote 0
Try:

Code:
Sub SheetCopier()
[COLOR=#333333]On Error GoTo GetOut[/COLOR]
   Dim x As Integer
   i = 0
   x = InputBox("Enter number of times to copy default sheet")
   For numtimes = 1 To x
      Ndate = Format(DateAdd("d", i, Date), "[$-409]mmmm d yyyy;@")
      ActiveWorkbook.Sheets("Default").Copy _
         Before:=ActiveWorkbook.Sheets("Default")
         ActiveSheet.Name = Ndate
         i = i + 1
   Next
[COLOR=#333333]GetOut:[/COLOR]
End Sub
 
Upvote 0
only one issue, if I cancel the script I get an error. "Type mismatch".......
 
Upvote 0
Try this
Code:
Sub SheetCopier()
   Dim x As Long
   Dim NumTimes As Long
   Dim DAns As String
   Dim XAns As String
   Dim Dt As Date
   
   DAns = InputBox("Please enter a date")
   If Len(DAns) = 0 Then Exit Sub
   Dt = CDate(DAns)
   XAns = InputBox("Enter number of times to copy default sheet")
   If Len(XAns) = 0 Then Exit Sub
   x = CLng(XAns)
   For NumTimes = 1 To x
      'Loop by using x as the index number to make x number copies.
      ActiveWorkbook.Sheets("Exist").Copy _
         Before:=ActiveWorkbook.Sheets("Exist")
    ActiveSheet.Name = Format(Dt + NumTimes - 1, "mmm-dd-yyyy")
         'Put copies in Before Default Sheet.
   Next
End Sub
 
Upvote 0
Thank You , I just added the "getout" to your original. I needed to be able to pick the date just to be on the safe side. :)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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