title: Hi I want to use VBA to count in a Pivot Table
body: <p>I can use VBA to write a coding for "Pog Group" and "Item#" in the row. Then I want to count houw many times the Item# repeat in each Pog Group by VBA in this Pivot table. I can sum them but I do not know how to count them. In the picture I showed below coding can realize the effect on the left Pivot Table, but I want to realize the effect on the right. Thank you so much for all your help!!!   </p>
  
  <pre><code>Sub creatpivottable2()
  
  Dim PT As PivotTable
  Dim PTCache As PivotCache
  Worksheets("SKU &amp; POG DataResource").Select
  
  Set PTCache = ActiveWorkbook.PivotCaches.Create(xlDatabase, Cells(1,  1).CurrentRegion)
  Set PT = ActiveSheet.PivotTables.Add(PivotCache:=PTCache,    TableDestination:=Range("E4"))
  
  With PT
  .PivotFields("POG Group").Orientation = xlRowField
  .PivotFields("Item #").Orientation = xlRowField
  .PivotFields("Trait #").Orientation = xlDataField
  
  
   End With
  
  
  End Sub
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/eoxlz.jpg" rel="nofollow">enter image description here</a></p>