PC Review


Reply
Thread Tools Rate Thread

Code to link Pivot page fields to DV Lists

 
 
EZ
Guest
Posts: n/a
 
      24th Jun 2009

I know this is pretty easy, but i'm kind of new to VBA



I have found this code in Debra Dalgleish Site.

It's about linking Pivot table page field to a cell dropdown list.

I need it modified to do multiple page fields...

Codes between $$ $$ are my attempt.



Private Sub Worksheet_Change(ByVal Target As Range)

Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String

strField = "Country"
$$ strField = "Location" $$
$$ strField = "Product" $$

or

$$ strField = ("Country","Location","Product") $$

or

$$ strField = MyRange (I have created a name range for B2:B4) $$



On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False

If Target.Address = Range("B2").Address Then
$$ If Target.Address = Range("B2:B4").Address Then $$
For Each ws In ThisWorkbook.Worksheets
For Each pt In ws.PivotTables
With pt.PageFields(strField)
For Each pi In .PivotItems
If pi.Value = Target.Value Then
.CurrentPage = Target.Value
Exit For
Else
.CurrentPage = "(All)"
End If
Next pi
End With
Next pt
Next ws

End If

Application.EnableEvents = True
Application.ScreenUpdating = True

End Sub

*******************

I also tried to use the same code 3 times (changing the variables to
something like ws2, ws3...) but didn't work either... not sure if it's
because the worksheet change event is private or...



Thanks.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot page fields! =?Utf-8?B?U2hhcm9u?= Microsoft Excel Programming 8 4th Jun 2008 09:31 PM
How to pull values from the pivot table fields, through the code/. =?Utf-8?B?c2V2ZW5fc25vdw==?= Microsoft Excel Programming 3 11th Apr 2006 12:46 PM
Link Page Fields to separate Pivot Tables xunzi Microsoft Excel Discussion 2 24th Feb 2006 06:42 PM
limiting pivot table results from multiple page field lists Dale Microsoft Excel Discussion 0 27th Sep 2005 11:44 PM
correct code to link 2 fields Erika Microsoft Access 0 29th Dec 2003 03:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:06 PM.