Grabbing the next column value in a pivot table

A

Alexandre

Hey i am currently using the following code,
and I would like to sum the values which are in the second column, i am
currently evaluating the first column,

==>

Sub PivotShowItemAllVisible()

Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next

Set pt = ActiveSheet.PivotTables("months_to_incorp_pivot")

Dim ECWI3Months As Integer
ECWI3Months = 0

For Each pf In pt.RowFields
pf.AutoSort xlManual, pf.SourceName
For Each pi In pf.PivotItems
Application.StatusBar = "Evaluating : " & pi.Name
If (pi.Value <= 3) Then
<==
THIS is where i want to sum the second column
==>

ECWI3Months = pi.Value + ECWI3Months
End If

pi.Visible = True
Next pi
Next pf
ActiveSheet.Range("D4:D4").Value = ECWI3Months
ActiveSheet.Range("B4:B4").Value = pt.GetData(pt.GrandTotalName)
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

<==

Using the folowing code how would i go about doing this ?


Regards,
Alexandre Brisebois
 
A

Alexandre

for anyone else woundering

using this line does the trick
ECWI3Months = pi.DataRange.Value + ECWI3Months

PivotItem.DataRange.Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top