I have a workbook with 7 sheets:
Result Page, DW-1, PROD-1, DW-2, PROD-2, IP-2, IP-1
The Results page from top down;
A1-4 contain Start Date, End Date, Year, and Month (this date information is used in the SQL queries to pull the correct
data.)
To their right is a Recalc button linked to Macro1
Under that, starting in A7 are the summation fields
Under that, starting at A30 are PivotTables.
DW-1, PROD-1, DW-2, PROD-2, IP-2, IP-1 Sheets contain the Raw data retrieved from SQL queries.
The problem i am having is that my Macro1 is not refreshing the data and pivot tables in the correct order... and thus my
results are not appearing correctly and i have to run the marco twice. I have noticed in some other posts that the code:
ActiveSheet.PivotTables("PivotTable-DW").RefreshTable
Has worked but in my instance they are returning and error:
Run-Time error '1004': Unable to get the PivotTables property of the Worksheet class
I have looked for this error online but have found nothing as far as a solution... does anyone have any suggestions,
please?
~~~~~~~~~~~
Macro1:
Sub Macro1()
'
' Macro1 Macro
'
Response = Application.InputBox("Please enter in the Start Date as: MM/DD/YYYY", "Start Date",
Range("A1").Value, 50, 150, "", , 1)
If Response <> False Then
ActiveSheet.Range("A1").Value = Response
Else
MsgBox ("Exiting Input! No Calculation will take place")
Exit Sub
End If
Response = Application.InputBox("Please enter in the End Date as: MM/DD/YYYY", "End Date",
Range("A2").Value, 50, 150, "", , 1)
If Response <> False Then
ActiveSheet.Range("A2").Value = Response
Else
MsgBox ("Exiting Input! No Calculation will take place")
Exit Sub
End If
'
ActiveWorkbook.RefreshAll
Calculate
'
Worksheets("Result Page").Select
ActiveSheet.PivotTables("PivotTable-DW").RefreshTable
ActiveSheet.PivotTables("PivotTable-MERCER").RefreshTable
ActiveSheet.PivotTables("PivotTable-AUTF").RefreshTable
ActiveSheet.PivotTables("PivotTable-HOMF").RefreshTable
ActiveSheet.PivotTables("PivotTable-FPIC").RefreshTable
ActiveSheet.PivotTables("PivotTable-iPartners").RefreshTable
ActiveSheet.PivotTables("PivotTable-DW-Written").RefreshTable
ActiveSheet.PivotTables("PivotTable-DW-Surcharge").RefreshTable
ActiveSheet.PivotTables("PivotTable-Mercer-Written").RefreshTable
ActiveSheet.PivotTables("PivotTable-Mercer-Surcharge").RefreshTable
' ActiveSheet.PivotTables("PivotTable-AUTF-Written").RefreshTable
' ActiveSheet.PivotTables("PivotTable-HOMF-Written").RefreshTable
ActiveSheet.PivotTables("PivotTable-FPIC-Written").RefreshTable
ActiveSheet.PivotTables("PivotTable-iPartners-Written").RefreshTable
ActiveSheet.PivotTables("PivotTable-iPartners-Surcharge").RefreshTable
ActiveSheet.Refresh
Calculate
Debug.Print "Macro1 ended"
End Sub