![]() |
How do I check Pivot Table existence?
Hi,
I'm trying to check if a pivot table named "MyPivot" exists in a given worksheet. I tried with: If worksheets("Pivot").PivotTables("MyPivot") is nothing then... Unfortunately Excel gives me an error, I think because it does not find the PivotTables("MyPivot"). Is there a way to check if a PivotTable exists? Thank you. |
How do I check Pivot Table existence?
How about using error trapping:
Dim Pivot_Found as Boolean On Error Goto Pivot_Not_Found Pivot_Found = False If worksheets("Pivot").PivotTables("MyPivot") is nothing then... ....your code here... Pivot_Found = True ' You made it here, so there was no error Pivot_Not_Found: If Not Pivot_Found Then msgbox "Error: Pivot Table Not Found!" Exit Sub Endif ....continue with your code... -=OR=- You could test Activesheet.PivotTables.Count if you know there is only one pivot table on the sheet. If it's zero, you know the pivot table isn't there. HTH, Eric |
How do I check Pivot Table existence?
I'd use something like:
Dim PT as pivottable set pt = nothing on error resume next set pt = worksheets("Pivot").PivotTables("MyPivot") on error goto 0 if pt is nothing then 'nope else 'yep end if Paolo Sardi wrote: Hi, I'm trying to check if a pivot table named "MyPivot" exists in a given worksheet. I tried with: If worksheets("Pivot").PivotTables("MyPivot") is nothing then... Unfortunately Excel gives me an error, I think because it does not find the PivotTables("MyPivot"). Is there a way to check if a PivotTable exists? Thank you. -- Dave Peterson |
All times are GMT +1. The time now is 05:15 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com