Code
-------------------
Sub pivot_count_columns()
'********Select the Pivot table*********
'using name of the pivot
'ActiveSheet.PivotTables("PivotTable4").PivotSelect PivotFields, xlDataAndLabel
'or using a known cell in the pivot
ActiveSheet.Range("q11").PivotTable.PivotSelect PivotFields, xlDataAndLabel
'if you want to count columns containing data only use xlDataOnly instead of xlDataAndLabel
'or if you want the number fo columns contining labels only use xlLabelOnly instead of xlDataAndLabel
'********Cont columns in selection**********
i = Selection.Columns.Count
'*********Check**********
MsgBox i
Debra and tg, Thanks. Would the same apply if you were wanting to count the
number of rows? Do I just replace the word columns with the word rows?
Thanks again.
Thanks, I am thrilled that I was able to figure out how to get it into VB on
my own!
Question - it seems to be counting the field names, grand totals too. Any
way to count just the items?
The below yielded a result of 12
Sum of Order Amount
Salesperson Total
Buchanan 68792.25
Callahan 123032.67
Davolio 182500.09
Dodsworth 75048.04
Fuller 162503.78
King 116962.99
Leverling 201196.27
Peacock 225763.68
Suyama 72527.63
Grand Total 1228327.4
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.