Create sheet after last sheet

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have a sheet called "Costing Sheet"

I have written code to put todays date - 5 days in col A1 on Sheet "Costing Sheet" and the copy the sheet after the last sheet and then to name sheet based on month and year in A1 for eg Oct-2019


I get an application defined or Object defined error and the following code is highlighted


Code:
.Name = .[a1].Text


See Full code below


Code:
 Sub AddSheet_Names()
 With Sheets("Costing Sheet")
 
    With Range("A1")
    .FormulaR1C1 = "=NOW()-5"
    With Range("A1")
    .NumberFormat = "mmm-yyyy"
 
Sheets("Costing Sheet").Copy , Sheets(Sheets.Count)
    With Sheets(Sheets.Count)
        .Name = .[a1].Text
        .Copy
        With ActiveWorkbook
            .SaveAs CreateObject("WScript.Shell").SpecialFolders("desktop") & _
                    "\" & .Sheets(1).[a1].Text & ".xlsx"
            .Close False
        End With
    End With
     End With
        End With
             End With
End Sub


It would be appreciated if someone could kindly amend my code
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try
Code:
 Sub AddSheet_Names()
    With Sheets("Costing Sheet")
        With .Range("A1")
            .FormulaR1C1 = "=today()-5"
            .NumberFormat = "mmm-yyyy"
        End With
        .Copy , Sheets(Sheets.Count)
    End With
    With ActiveSheet
        .Name = .[a1].Text
        .Copy
    End With
    With ActiveWorkbook
        .SaveAs CreateObject("WScript.Shell").SpecialFolders("desktop") & _
        "\" & .Sheets(1).[a1].Text & ".xlsx"
        .Close False
    End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,670
Members
452,993
Latest member
FDARYABEE

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