Hi all,
My question can basically be simplified to asking the difference between a couple ways of writing code, which seem identical to me but one works and one does not.
Adding a field called "User Id" to the table, Excel usually makes this a sum because it is all numbers. However, sometimes it will have a cell of text, and then excel will default the field to count. So, trying to make sure "Count" is always its function:
[pre]
[/pre]
This is because the pivot field's name changes to "Sum of User Id". I tried to loop through PivotFields looking for "Sum of", but I see with the MsgBox function that it is looping through the items in the Pivot menu...which is still "User Id" of course.
Can someone please clarify how VBA distinguishes pivotfields being used in the table, and the list of pivotfields in the list to the right? When I use the .Orientation method the list on the right is used, but trying .Function creates an error since its only looking at whats used in the table.
Thanks for any explanation.
My question can basically be simplified to asking the difference between a couple ways of writing code, which seem identical to me but one works and one does not.
Adding a field called "User Id" to the table, Excel usually makes this a sum because it is all numbers. However, sometimes it will have a cell of text, and then excel will default the field to count. So, trying to make sure "Count" is always its function:
[pre]
Code:
With .PivotFields("User Id")
.Orientation = xlDataField
.Function = xlCount
End With
The above code works. The below code does not:
.PivotFields("User Id").Orientation = xlDataField
.PivotFields("User Id").Function = xlCount
This is because the pivot field's name changes to "Sum of User Id". I tried to loop through PivotFields looking for "Sum of", but I see with the MsgBox function that it is looping through the items in the Pivot menu...which is still "User Id" of course.
Can someone please clarify how VBA distinguishes pivotfields being used in the table, and the list of pivotfields in the list to the right? When I use the .Orientation method the list on the right is used, but trying .Function creates an error since its only looking at whats used in the table.
Thanks for any explanation.