LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Updating Pivot Tables via VBA

Hi,

I currently have code that updates page fields (i.e. page filters, not pivot
items) for pivot tables. I realize that I can't use this code to update pivot
items (non-page filters).

Cell I2 (on the same page as the pivot tables) has a drop-down list that
allows the user to choose an item for the page filters for three adjacent
pivot tables on one worksheet. But cells J2, K2, and L2 have drop-down lists
for pivot fields and thus I can't use the code below to adjust pivot items.
How do I adjust the code below to allow the user to not only adjust the page
filter (in cell I2), but also pivot fields in drop-down lists in cells J2, K2
and L2? Below is the code:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim strField As String
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'On Error Resume Next
If Target.Address = Range("I2").Address Then
strField = "Source of Funds"
Set ws = ActiveSheet
For Each pt In ws.PivotTables
With pt.PageFields(strField)
For Each pi In .PivotItems
If pi.Value = Target.Value Then
..CurrentPage = pi.Value 'Target.Value
Exit For
Else
..CurrentPage = "(All)"
End If
Next pi
End With
Next pt
Call Formatting
End If


Many thanks!
Kent.


-
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating pivot items on 3 pivot tables contained on one sheet klysell Excel Programming 2 August 9th 07 07:00 PM
Updating pivot items in three pivot tables on one sheet via VBA klysell Excel Programming 0 August 8th 07 07:20 PM
updating pivot tables ILoveAmerica!!! Excel Discussion (Misc queries) 0 October 11th 06 07:19 PM
updating pivot tables jgibbings Excel Discussion (Misc queries) 3 May 9th 05 11:02 PM
Updating Pivot-Tables Rafael Chang Excel Programming 1 September 8th 03 09:13 AM


All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"