Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want pivot table to count instead of sum

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
I have a module that creates a pivot table. I am new to VBA in EXCEL. I am an ACCESS, SQL Server programmer. My code works, but it sums my data field and I want it to count it instead. Can I override this in my code?

Thanks.

ProDev, MS Access Applications
Visit me at ==> Contact me at ==>lonniejohnson@prodev.us

May God bless you beyond your imagination!!!
 
This is what the macro recorder spat out - I double clicked on the 'Sum of Amount' field in the pivot table to bro#ing up the pivottable field options and selected 'count' so perhaps you could work it into your macro

Sub Macro4()
Range("G1").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Amount").Function = _
xlCount
End Sub

HTH
 
that's right the pivotfield object has the Function property taking the xlCount value to make it count. You need to set up your pivot table object variables first
Stephen Roman has an excelent chapter(20) on pivot tables in Writing Excel Macros.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top