ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Counting Data Field within a Pivot Table (https://www.excelbanter.com/excel-programming/293585-counting-data-field-within-pivot-table.html)

ExcelMonkey[_106_]

Counting Data Field within a Pivot Table
 
I have a routine that checks all the names of a pivot table's dat
fields (See Below). How can I count the number of data fields withi
the For Each Loop?



Sub DisplayDataFields()
Dim x As Variant
Dim Pivot1 As PivotTable
Set Pivot1 = Worksheets("Sheet1").PivotTables("Pivot Table 1")
For Each x In Pivot1.DataFields
'Display pivot field source name (name of field in original
'data)
MsgBox "Pivotfield SourceName is " & x.SourceName
Next
End Su

--
Message posted from http://www.ExcelForum.com


LEB

Counting Data Field within a Pivot Table
 
Seems you could just DIM another as an integer:

Dim counter as integer

The increment the variable each time the loop iterates:

counter=counter+1

If you do this before the MsgBox is displayed, you could
also display the count value in the MsgBox.-----Original
Message-----
I have a routine that checks all the names of a pivot

table's data
fields (See Below). How can I count the number of data

fields within
the For Each Loop?



Sub DisplayDataFields()
Dim x As Variant
Dim Pivot1 As PivotTable
Set Pivot1 = Worksheets("Sheet1").PivotTables("Pivot

Table 1")
For Each x In Pivot1.DataFields
'Display pivot field source name (name of field in

original
'data)
MsgBox "Pivotfield SourceName is " & x.SourceName
Next
End Sub


---
Message posted from http://www.ExcelForum.com/

.


ExcelMonkey[_107_]

Counting Data Field within a Pivot Table
 
Thank-yo

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com