copying sheets and changing date information on them

Enzo_Matrix

Board Regular
Joined
Jan 9, 2018
Messages
113
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Day[/TD]
[TD]Total Orders[/TD]
[TD]Total Late[/TD]
[TD]% Late[/TD]
[TD]% on-time[/TD]
[/TR]
[TR]
[TD]February 1, 2018[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]February 2, 2018[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]February 3, 2018[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Average on-time %[/TD]
[TD]#DIV/0![/TD]
[/TR]
</tbody>[/TABLE]

I use a table similar to this each month (entire date range of the month) to calculate our companies on-time delivery percentage.
I want to use VBA to duplicate this table and switch it to the next months information automatically.

After it's created, I need it to do a few things.
1. E5 (in the example table above) to reference a different sheet, in the same workbook that is used as a month by month comparison.
2. PivotTable data source gets changed to new sheet that was just created

This is what the Macro recorder generated but it only works for the one month.
Code:
Sub NewMonth() '' NewMonth Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
    Sheets(2).Select
    Sheets(2).Copy Before:=Sheets(3)
    Sheets(3).Select
    Sheets(3).Name = "March - On-Time"
    ActiveCell.FormulaR1C1 = "March - Mississauga"
    Range("A4").Select
    ActiveCell.FormulaR1C1 = "3/1/2018"
    Range("A5").Select
    ActiveCell.FormulaR1C1 = "3/2/2018"
    Range("A4:A5").Select
    Selection.AutoFill Destination:=Range("A4:A23"), Type:=xlFillDefault
    Range("A4:A23").Select
    Range("I2").Select
    ActiveSheet.PivotTables("PivotTable3").ChangePivotCache ActiveWorkbook. _
        PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "C:\Users\jbotha\Desktop\on-time\[Blank template.xlsm]March - On-Time!R3C1:R23C5" _
        , Version:=xlPivotTableVersion15)
    Sheets("Month By Month Comparison").Select
    Range("C5").Select
    ActiveCell.FormulaR1C1 = "='March - On-Time'!R[20]C[2]"
    Range("C6").Select
    Sheets("Feb - On-Time").Select
    ActiveWindow.SelectedSheets.Visible = False
End Sub


I have this for a new day sheet and I'm wondering if it's possible to modify it for a month sheet instead of a day sheet.
Code:
Sub NewDay() '' NewDay Macro
' Button that initiates new day set up for on-time delivery reports
'
' Keyboard Shortcut: Ctrl+Shift+A
'
   Sheets(Format(Date, "mmm dd, yyyy")).Copy Before:=Sheets(Sheets.Count)
   ActiveSheet.Name = Format(Date + 1, "mmm dd, yyyy")
   Range("B2").Select
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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