I have a pivot table that populates data in a tool that I am working on.. I have the following code updates that refreshes and update the pivot table when I add a record to he data
Sub RefreshTable()
Worksheets("Sheet1").PivotTables("PivotTable1").RefreshTable
Worksheets("Sheet1").PivotTables("PivotTable1").Update
End sub
When I physically delete "all the records" from the source table, the above code generates an error since there is no records to deal with. I need to modify the code to account for this scenario and avoid code crash by either hiding the entire pivot table or show as blank instead of refreshing ..
In case it helps, I have a variable called “nrec” that stores the number of data records. You may find something like the following helpful:
If nrec > 0 Then
' There are records
Worksheets("Sheet1").PivotTables("PivotTable1").RefreshTable
Worksheets("Sheet1").PivotTables("PivotTable1").Update
Else
' Need code here..
End IF
Bookmarks