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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot Table Count change to Sum

Status
Not open for further replies.

remeng

Technical User
Jul 27, 2006
520
US
Hi all,

I have a question about pivot tables. I have automatically generated a pivot table and depending on the inputs, the pivot table sometimes sets itself to count and other times sets itself to sum. I would like to add some code in so that it will check for the state and change it to Sum. Here is what I have tried. Thank you in advance!


Code:
  If ActiveSheet.PivotTables("X Offset PT").PivotFields("Sum of X Offset").Function _
        = xlCount Then
    ActiveSheet.PivotTables("X Offset PT").PivotFields("Count of X Offset"). _
        Function = xlSum
    Else: End If
 
so i have kept playing and have tried this, but it gives me an error at the first line.



Code:
If ActiveSheet.PivotTables("X Offset PT").PivotFields("Count of X Offset").Function _
                  = xlCount Then
    ActiveSheet.PivotTables("X Offset PT").PivotFields("Count of X Offset").Function _
                  = xlSum
    
ElseIf ActiveSheet.PivotTables("X Offset PT").PivotFields("Sum of X Offset").Function _
                  = xlSum Then End
 
Else: End If

The problem I think is do to the Pivot Field section being dynamic. Is there a way to look it up so that the conditions will work?

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top