Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-02-13
3
Medium Priority
?
2,298 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:Murray Brown
3 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 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:Murray Brown
ID: 40609671
Thanks very much
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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…

782 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