Solved

Excel VBA Check if the active sheet has a pivot table on it

Posted on 2015-02-13
3
1,424 Views
Last Modified: 2016-02-10
Hi

What Excel VBA code would I use to check if the active sheet has a pivot table on it?

Thanks
0
Comment
Question by:murbro
3 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40607758
if activesheet.pivottables().count>0 then
  'YES, THERE IS ONE.
else
  'NO, THERE ISN'T
End If
0
 
LVL 11

Expert Comment

by:Wilder1626
ID: 40607760
Hi

another way would be something like below. It would tell you in a Pop up message the Sheet name and the Pivot Table name if one or more exists:
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

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 40609671
Thanks very much
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question