I have a pivot table that has been working for quite a while without any problems. Clients now wish to have the report for a dynamic and specific subset of data based on date range. In other pivot tables, I have been able to filter without problems but this one does not allow for date filtering.
The table is built from up to 93 different sheets using the same range on each sheet, same columns, etc. Each sheet is the data for one date. The data includes equipment/employee usage and time with different columns for rates like Standard Time, Overtime, Double Time, etc. The hours for each are totalled and the total dollars for each row are totalled.
Client originally had all sheets included for the entire project. Now they wish to provide their client with probably weekly totals (possibly just a couple of days). I just can't figure out how to narrow down the reporting.
The pivot table fields end up with Row, Column and Value. I have put them in the appropriate areas of Row labels, Column labels and Values (formatted as Sum). I cannot access any specific column so I cannot add the date to the columns. The left column of the pivot table is the description of the equipment or operator's name and other columns are sum of hours and total dollars.
I have recorded a macro to determine how to code the pivot table and when narrowed down to three dates, I get the following:
Once a user enters a date on a sheet, the sheet name gets that date with the following code in the SheetChange event.
Because my client wishes to use a date range, I have set up a couple of fields for them to enter a start date and end date. I am trying to figure out how to turn those into sheet names for the code above. I tried to use a variable as the array so I could do something like
but I get the error Cannot open PivotTable source file '".xls'Dec 1, 2016" on the ActiveSheet.PivotTableWizard line.
Ultimately I would just like to build strArray in code based on the date ranges selected and any sheet that matches a date would be added to the array, but I am stuck on this error based on just three sheets that do exist.
Can anyone point me in the correct direction or provide an alternative angle? Sorry my question ended up being so long.
TIA rasinc
The table is built from up to 93 different sheets using the same range on each sheet, same columns, etc. Each sheet is the data for one date. The data includes equipment/employee usage and time with different columns for rates like Standard Time, Overtime, Double Time, etc. The hours for each are totalled and the total dollars for each row are totalled.
Client originally had all sheets included for the entire project. Now they wish to provide their client with probably weekly totals (possibly just a couple of days). I just can't figure out how to narrow down the reporting.
The pivot table fields end up with Row, Column and Value. I have put them in the appropriate areas of Row labels, Column labels and Values (formatted as Sum). I cannot access any specific column so I cannot add the date to the columns. The left column of the pivot table is the description of the equipment or operator's name and other columns are sum of hours and total dollars.
I have recorded a macro to determine how to code the pivot table and when narrowed down to three dates, I get the following:
Code:
ActiveSheet.PivotTableWizard SourceType:=xlConsolidation, SourceData:=Array _
("'Dec 1, 2016'!R9C2:R48C14", "'Dec 6, 2016'!R9C2:R48C14", _
"'Dec 8, 2016'!R9C2:R48C14")
With ActiveSheet.PivotTables("ptSummary").PivotFields("Row")
.PivotItems("(blank)").Visible = False
End With
Once a user enters a date on a sheet, the sheet name gets that date with the following code in the SheetChange event.
Code:
strSheetName = Format(Sh.Range("F4").Value, "MMM d, yyyy")
Sh.Name = strSheetName
Because my client wishes to use a date range, I have set up a couple of fields for them to enter a start date and end date. I am trying to figure out how to turn those into sheet names for the code above. I tried to use a variable as the array so I could do something like
Code:
strArray = """'Dec 1, 2016'!R9C2:R48C14""" & ", " & """'Dec 6, 2016'!R9C2:R48C14""" & ", " & """'Dec 8, 2016'!R9C2:R48C14"""
ActiveSheet.PivotTableWizard SourceType:=xlConsolidation, SourceData:=Array _
(strArray)
With ActiveSheet.PivotTables("ptSummary").PivotFields("Row")
.PivotItems("(blank)").Visible = False
End With
but I get the error Cannot open PivotTable source file '".xls'Dec 1, 2016" on the ActiveSheet.PivotTableWizard line.
Ultimately I would just like to build strArray in code based on the date ranges selected and any sheet that matches a date would be added to the array, but I am stuck on this error based on just three sheets that do exist.
Can anyone point me in the correct direction or provide an alternative angle? Sorry my question ended up being so long.
TIA rasinc