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.
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.
<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