Macro that duplicates spread sheet and renames it

  • Thread starter Thread starter Legacy 185660
  • Start date Start date
L

Legacy 185660

Guest
Hey again!
I need help with a simple macro, this is kind of 2 questions
I need a macro that will duplicate a sheet called "Template" and rename it as (Not sure how strings/macros work on excel so here is a rough interpretation based on my limited excel knowledge) Today() & " - " & Today + 4

So if i ran that script today it would duplicate the template and name it July 7 - July 11


Also, if anyone has any links to tutorials on macros, I would really like to learn
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this

Code:
Sub test()
Sheets("Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Format(Date, "mmmm dd") & " - " & Format(Date + 4, "mmmm dd")
End Sub
 
Upvote 0
This is again, on google docs and is a tiny bit different

So do I just paste the code between

Code:
function myFunction() {

}
 
Upvote 0
Actually I don't think google docs has any of the functionality.
Thanks anyways!
 
Upvote 0
Ill be doing this in regular excel now, is there also an option that will automatically fill in the cell B2 with todays date?
 
Upvote 0
Try

Code:
Sub test()
Sheets("Template").Copy after:=Sheets(Sheets.Count)
With ActiveSheet
    .Name = Format(Date, "mmmm dd") & " - " & Format(Date + 4, "mmmm dd")
    .Range("B2").Value = Date
End With
End Sub
 
Upvote 0
Thanks! I mucked around with it a bit after that and made it so that it would auto update every monday on start up

Code:
[INDENT]Private Sub Workbook_Open()

'Checks if todays date is Monday, and will create a new sheet based on template
If Format(Date, "dddd") = "Monday" Then
    Call Duplicate_Template
End If

End Sub

[/INDENT] 
 Public Sub Duplicate_Template()

    Dim sh As Worksheet
    Dim name As String
    Dim nameTaken As Boolean
    
    'Will format date to "Dec 27 - 31" if it falls within same month, or "Dec 31 - Jan 4" if it does not
    If Format(Date, "mmm") = Format(Date + 4, "mmm") Then
        name = Format(Date, "mmm dd") & " - " & Format(Date + 4, "dd")
    Else
        name = Format(Date, "mmm dd") & " - " & Format(Date + 4, "mmm dd")
    End If
    
    For Each sh In Worksheets
        If [URL="http://sh.name/"]sh.name[/URL] Like name Then
            'Checks each sheet to make sure that the new sheet has not already been created
            nameTaken = True
            Exit For
        End If
    Next
    
    If nameTaken = False Then
            'If name is not taken, then it will create a duplicate of the template
            Sheets("Template").Copy after:=Sheets("Template")
            With ActiveSheet
                'Creates name of spreadsheet according to date
                .name = name
                'Inputs current date into cell "C1" to help populate graphs
                .Range("C1").Value = Date
            End With
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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