copying sheets and changing date information on them

Enzo_Matrix

Board Regular
Joined
Jan 9, 2018
Messages
113
DayTotal OrdersTotal Late% Late% on-time
February 1, 2018
February 2, 2018
February 3, 2018
Average on-time %#DIV/0!

<tbody>
</tbody>

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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,215,465
Messages
6,124,982
Members
449,201
Latest member
Lunzwe73

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