Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Range existence check | Excel Programming | |||
Check for existence | Excel Discussion (Misc queries) | |||
VBA to check for existence of a DSN | Excel Programming | |||
How do I check for existence of a worksheet? | Excel Worksheet Functions | |||
Code to check existence | Excel Programming |