pivottable page fields

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

Is there any way to return the actual page field that was
changed from the Private Sub Worksheet_Change(ByVal
Target As Range) procedure?

The value Target returns is the entire range of the
pivottable, not just the page field range cell that was
changed.

Any ideas?

Grant.
 
You could use a module level variable to track the page field values.
For example:

'===========================
Option Explicit
Dim mvPivotPage1 As Variant
Dim mvPivotPage2 As Variant

Private Sub Worksheet_Change(ByVal Target As Range)
Dim pt As PivotTable
Dim pf1 As PivotField
Dim pf2 As PivotField

Set pt = ActiveSheet.PivotTables(1)
Set pf1 = pt.PageFields(1)
Set pf2 = pt.PageFields(2)

If LCase(pf1.CurrentPage) _
<> LCase(mvPivotPage1) Then
MsgBox "Page field " & pf1.Name & " was changed"
Else
If LCase(pf2.CurrentPage) _
<> LCase(mvPivotPage2) Then
MsgBox "Page field " & pf2.Name & " was changed"
End If
End If
mvPivotPage1 = pf1.CurrentPage
mvPivotPage2 = pf2.CurrentPage

End Sub
'=============================
 

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

Back
Top