Solved

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

Posted on 2015-02-13
3
1,531 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

710 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