Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Marcus Langell
 
Posts: n/a
Default Avoid renaming page fields

Hi!
I have a macro that switches pages in a pivot table, which works as long as
there is a matching page name for the string the macro wants to enter. When
there is no such page, the macro simply changes the name of the current page.
Do you have any ideas on how to avoid this? (I tried looping through the
PivotItems to verify my input but it seems as if old items are cached, I only
want to get the pages possible to choose in the current pivot table.)
Thankful for ideas!

/Marcus
  #2   Report Post  
Posted to microsoft.public.excel.misc
Debra Dalgleish
 
Posts: n/a
Default Avoid renaming page fields

You can prevent or remove old items from the pivot table:

http://www.contextures.com/xlPivot04.html

When changing pages, test for the item before setting the page. For example:

Sub ChangePivotPage()
'Test if Item exists
'before setting the CurrentPage to that item
On Error Resume Next
Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim str As String
Set ws = ActiveSheet
Set pt = ws.PivotTables(1)
str = ws.Range("B1").Value

On Error Resume Next

With pt.PageFields("Region")
Set pi = .PivotItems(str)
On Error GoTo 0
If pi Is Nothing Then
.CurrentPage = "(All)"
Else
.CurrentPage = str
End If
End With

End Sub


Marcus Langell wrote:
Hi!
I have a macro that switches pages in a pivot table, which works as long as
there is a matching page name for the string the macro wants to enter. When
there is no such page, the macro simply changes the name of the current page.
Do you have any ideas on how to avoid this? (I tried looping through the
PivotItems to verify my input but it seems as if old items are cached, I only
want to get the pages possible to choose in the current pivot table.)
Thankful for ideas!

/Marcus



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

  #3   Report Post  
Posted to microsoft.public.excel.misc
Marcus Langell
 
Posts: n/a
Default Avoid renaming page fields

That's also wonderful, thanks a million!

"Debra Dalgleish" wrote:

You can prevent or remove old items from the pivot table:

http://www.contextures.com/xlPivot04.html

When changing pages, test for the item before setting the page. For example:

Sub ChangePivotPage()
'Test if Item exists
'before setting the CurrentPage to that item
On Error Resume Next
Dim ws As Worksheet
Dim pt As PivotTable
Dim pi As PivotItem
Dim str As String
Set ws = ActiveSheet
Set pt = ws.PivotTables(1)
str = ws.Range("B1").Value

On Error Resume Next

With pt.PageFields("Region")
Set pi = .PivotItems(str)
On Error GoTo 0
If pi Is Nothing Then
.CurrentPage = "(All)"
Else
.CurrentPage = str
End If
End With

End Sub


Marcus Langell wrote:
Hi!
I have a macro that switches pages in a pivot table, which works as long as
there is a matching page name for the string the macro wants to enter. When
there is no such page, the macro simply changes the name of the current page.
Do you have any ideas on how to avoid this? (I tried looping through the
PivotItems to verify my input but it seems as if old items are cached, I only
want to get the pages possible to choose in the current pivot table.)
Thankful for ideas!

/Marcus



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html


Reply
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
Problem with Page Numbering Aurora Excel Discussion (Misc queries) 0 November 21st 05 02:10 PM
Page Numbers Aurora Excel Discussion (Misc queries) 0 November 17th 05 08:04 PM
Pivot Table Page fields Ajit Excel Discussion (Misc queries) 1 October 12th 05 05:49 PM
Why do old, unused values still show in my Pivot Page fields? NateBrei Excel Discussion (Misc queries) 3 August 10th 05 04:18 PM
How to remove Drop Page Fields Here from Pivot Table wengyee Excel Discussion (Misc queries) 2 June 3rd 05 10:36 PM


All times are GMT +1. The time now is 05:47 PM.

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

About Us

"It's about Microsoft Excel"