Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Determine If Pivot Table Exists

Hey,

I need to loop through all the worksheets in a workbook and for each
worksheet with a pivot table I want to cleanup the pivot cache.

I've done this for workbooks where all the worksheets have a pivot table but
I'm having trouble doing this where some worksheets have a pivot table and
some don't. My guess is I need to determine if a worksheet has a pivot table
and if it does clean it up otherwise move on to the next spreadsheet.

I'm converting existing VBA code to VB.NET 2005 so an example using either
language would work for me.

Thanks for the help!

--
-ridawg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Determine If Pivot Table Exists

dim wks as worksheet
dim iCtr as long
for each wks in activeworkbook.worksheets
for iCtr = 1 to wks.pivottables.count
next ictr
next wks

Or if you just want to check...

if wks.pivottables.count 0 then
'it has at least one pt
end if


ridawg wrote:

Hey,

I need to loop through all the worksheets in a workbook and for each
worksheet with a pivot table I want to cleanup the pivot cache.

I've done this for workbooks where all the worksheets have a pivot table but
I'm having trouble doing this where some worksheets have a pivot table and
some don't. My guess is I need to determine if a worksheet has a pivot table
and if it does clean it up otherwise move on to the next spreadsheet.

I'm converting existing VBA code to VB.NET 2005 so an example using either
language would work for me.

Thanks for the help!

--
-ridawg


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,118
Default Determine If Pivot Table Exists

Maybe something like this?:

'--------Start of Code-----------
Sub ListPvtTblSheets()
Dim shtWS As Worksheet
Dim pvtPT As PivotTable
Dim strMsg As String

strMsg = ""

For Each shtWS In ThisWorkbook.Worksheets
If shtWS.PivotTables.Count 0 Then
strMsg = strMsg & shtWS.Name & vbCr
For Each pvtPT In shtWS.PivotTables
strMsg = strMsg & "-" & pvtPT.Name & vbCr
Next pvtPT
End If
Next shtWS

MsgBox strMsg
End Sub
'--------End of Code-----------

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"ridawg" wrote:

Hey,

I need to loop through all the worksheets in a workbook and for each
worksheet with a pivot table I want to cleanup the pivot cache.

I've done this for workbooks where all the worksheets have a pivot table but
I'm having trouble doing this where some worksheets have a pivot table and
some don't. My guess is I need to determine if a worksheet has a pivot table
and if it does clean it up otherwise move on to the next spreadsheet.

I'm converting existing VBA code to VB.NET 2005 so an example using either
language would work for me.

Thanks for the help!

--
-ridawg

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Determine If Pivot Table Exists

Dim sh as Worksheet, pt as PivotTable
for each sh in worksheets
if sh.PivotTables.count 1 then
for each pt in sh.PivotTables


Next
end if
Next

--
Regards,
Tom Ogilvy


"ridawg" wrote:

Hey,

I need to loop through all the worksheets in a workbook and for each
worksheet with a pivot table I want to cleanup the pivot cache.

I've done this for workbooks where all the worksheets have a pivot table but
I'm having trouble doing this where some worksheets have a pivot table and
some don't. My guess is I need to determine if a worksheet has a pivot table
and if it does clean it up otherwise move on to the next spreadsheet.

I'm converting existing VBA code to VB.NET 2005 so an example using either
language would work for me.

Thanks for the help!

--
-ridawg

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Determine If Pivot Table Exists

Thanks for the help!

I was able to get this to work with a little trial error. Just what I needed.

--
-ridawg


"Dave Peterson" wrote:

dim wks as worksheet
dim iCtr as long
for each wks in activeworkbook.worksheets
for iCtr = 1 to wks.pivottables.count
next ictr
next wks

Or if you just want to check...

if wks.pivottables.count 0 then
'it has at least one pt
end if


ridawg wrote:

Hey,

I need to loop through all the worksheets in a workbook and for each
worksheet with a pivot table I want to cleanup the pivot cache.

I've done this for workbooks where all the worksheets have a pivot table but
I'm having trouble doing this where some worksheets have a pivot table and
some don't. My guess is I need to determine if a worksheet has a pivot table
and if it does clean it up otherwise move on to the next spreadsheet.

I'm converting existing VBA code to VB.NET 2005 so an example using either
language would work for me.

Thanks for the help!

--
-ridawg


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
determine in datasource or pivot table rodchar Excel Discussion (Misc queries) 0 March 23rd 09 05:34 PM
determine the name of the selected pivot table Tim879 Excel Discussion (Misc queries) 1 September 23rd 07 05:02 PM
VBA:: determine if UDF exists? George[_3_] Excel Discussion (Misc queries) 1 May 7th 07 12:57 PM
determine if value exists geebee Excel Programming 2 September 19th 06 11:03 PM
If Pivot Table Exists hoppermr Excel Programming 4 June 27th 06 05:47 PM


All times are GMT +1. The time now is 03:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"