Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default Pivot page fields!

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Pivot page fields!

There are a couple of approaches. One is to loop through the PivotFields
collection for your pivot table using a For Each loop (the code would be
something like:

Dim myField As PivotField
For Each myField In Worksheets("sheet3").PivotTables(1)
If myField.Name = "xxx" Then
....
....
Endif
Next

If you do this, if the name doesn't exist the code won't fall over, just
move on.

Alternatively make a note of the error code number and use error trapping:

Sub ...
On Error Goto handler

[your macro]

Exit Sub

handler:
If Err.Number = xxx Then
Resume Next
End If

End Sub

But I think the For loop's the best solution.

"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Pivot page fields!

Hi Martin!

I have a small problem similar to this question. I want to make some items
visible and some not visible. I know all possible items but I dont know if
they exist as a pivotitem in a certain time. so... I thought that I could use
ure example with For Each but For Each PivotItem instead of For Each
PivotField... This is my code sample:

Dim itm As PivotItem

For Each itm In Worksheets("xxx").PivotTables("yyy"). _
PivotFields("zzz")

If itm.Name = "vvv" Then itm.Visible = True
If itm.Name = "uuu" Then itm.Visible = False
...
...
Next

The error says number 438.

Appreciate your help!!!
Thanks!
//Jonas

"Martin" wrote:

There are a couple of approaches. One is to loop through the PivotFields
collection for your pivot table using a For Each loop (the code would be
something like:

Dim myField As PivotField
For Each myField In Worksheets("sheet3").PivotTables(1)
If myField.Name = "xxx" Then
....
....
Endif
Next

If you do this, if the name doesn't exist the code won't fall over, just
move on.

Alternatively make a note of the error code number and use error trapping:

Sub ...
On Error Goto handler

[your macro]

Exit Sub

handler:
If Err.Number = xxx Then
Resume Next
End If

End Sub

But I think the For loop's the best solution.

"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Pivot page fields!

Hi Again!

I must have been tired... Found the novice problem as soon I took a break
and returned to my nice program! Thanks...

//Jonas

"olssonj" wrote:

Hi Martin!

I have a small problem similar to this question. I want to make some items
visible and some not visible. I know all possible items but I dont know if
they exist as a pivotitem in a certain time. so... I thought that I could use
ure example with For Each but For Each PivotItem instead of For Each
PivotField... This is my code sample:

Dim itm As PivotItem

For Each itm In Worksheets("xxx").PivotTables("yyy"). _
PivotFields("zzz")

If itm.Name = "vvv" Then itm.Visible = True
If itm.Name = "uuu" Then itm.Visible = False
...
...
Next

The error says number 438.

Appreciate your help!!!
Thanks!
//Jonas

"Martin" wrote:

There are a couple of approaches. One is to loop through the PivotFields
collection for your pivot table using a For Each loop (the code would be
something like:

Dim myField As PivotField
For Each myField In Worksheets("sheet3").PivotTables(1)
If myField.Name = "xxx" Then
....
....
Endif
Next

If you do this, if the name doesn't exist the code won't fall over, just
move on.

Alternatively make a note of the error code number and use error trapping:

Sub ...
On Error Goto handler

[your macro]

Exit Sub

handler:
If Err.Number = xxx Then
Resume Next
End If

End Sub

But I think the For loop's the best solution.

"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Pivot page fields!

I think you stated the problem clearly - however, apparently you didn't
understand the answer. Her is some sample code that may provide a clue:

Sub MatchPages()
Dim s As String
s = ActiveSheet.PivotTables(1).PageFields(1).CurrentPa ge
Debug.Print s
For Each sh In ActiveWorkbook.Worksheets
If sh.Name < ActiveSheet.Name Then
For Each pvt In sh.PivotTables
If s = "(All)" Then
pvt.PageFields(1).CurrentPage = "(All)"
Else
For Each pitm In pvt.PageFields(1).PivotItems
If pitm.Value = s Then
pvt.PageFields(1).CurrentPage = pitm.Value
Exit For
End If
Next
End If
Next
End If
Next

End Sub

--
Regards,
Tom Ogilvy


"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default Pivot page fields!

Hi Tom and Martin

I didn't know there was an answer!! I am going to try both methods and see.
Thank you both for your help. Tom - you are a wonder!!

Sharon
--
Sharon


"Tom Ogilvy" wrote:

I think you stated the problem clearly - however, apparently you didn't
understand the answer. Her is some sample code that may provide a clue:

Sub MatchPages()
Dim s As String
s = ActiveSheet.PivotTables(1).PageFields(1).CurrentPa ge
Debug.Print s
For Each sh In ActiveWorkbook.Worksheets
If sh.Name < ActiveSheet.Name Then
For Each pvt In sh.PivotTables
If s = "(All)" Then
pvt.PageFields(1).CurrentPage = "(All)"
Else
For Each pitm In pvt.PageFields(1).PivotItems
If pitm.Value = s Then
pvt.PageFields(1).CurrentPage = pitm.Value
Exit For
End If
Next
End If
Next
End If
Next

End Sub

--
Regards,
Tom Ogilvy


"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Pivot page fields!

Well, it appears that Martin understood you to say the Pivot Field itself
doesn't exist. I understood you to say an item in a pagefield does not
exist.

Also, Martin's code is pseudo code and will not run as written, so you would
need to clean it up.

--
Regards,
Tom Ogilvy


"Sharon" wrote:

Hi Tom and Martin

I didn't know there was an answer!! I am going to try both methods and see.
Thank you both for your help. Tom - you are a wonder!!

Sharon
--
Sharon


"Tom Ogilvy" wrote:

I think you stated the problem clearly - however, apparently you didn't
understand the answer. Her is some sample code that may provide a clue:

Sub MatchPages()
Dim s As String
s = ActiveSheet.PivotTables(1).PageFields(1).CurrentPa ge
Debug.Print s
For Each sh In ActiveWorkbook.Worksheets
If sh.Name < ActiveSheet.Name Then
For Each pvt In sh.PivotTables
If s = "(All)" Then
pvt.PageFields(1).CurrentPage = "(All)"
Else
For Each pitm In pvt.PageFields(1).PivotItems
If pitm.Value = s Then
pvt.PageFields(1).CurrentPage = pitm.Value
Exit For
End If
Next
End If
Next
End If
Next

End Sub

--
Regards,
Tom Ogilvy


"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default Pivot page fields!

Hi Tom you are right. It is when an item in a pagefield doesn't exist. I
am going over your code now to work in the variable that captures the
required item in the first place, i.e. when the user clicks on a button, the
item is captured in a variable. Thanks a lot. I know it is going to work
beautifully.
--
Sharon


"Tom Ogilvy" wrote:

Well, it appears that Martin understood you to say the Pivot Field itself
doesn't exist. I understood you to say an item in a pagefield does not
exist.

Also, Martin's code is pseudo code and will not run as written, so you would
need to clean it up.

--
Regards,
Tom Ogilvy


"Sharon" wrote:

Hi Tom and Martin

I didn't know there was an answer!! I am going to try both methods and see.
Thank you both for your help. Tom - you are a wonder!!

Sharon
--
Sharon


"Tom Ogilvy" wrote:

I think you stated the problem clearly - however, apparently you didn't
understand the answer. Her is some sample code that may provide a clue:

Sub MatchPages()
Dim s As String
s = ActiveSheet.PivotTables(1).PageFields(1).CurrentPa ge
Debug.Print s
For Each sh In ActiveWorkbook.Worksheets
If sh.Name < ActiveSheet.Name Then
For Each pvt In sh.PivotTables
If s = "(All)" Then
pvt.PageFields(1).CurrentPage = "(All)"
Else
For Each pitm In pvt.PageFields(1).PivotItems
If pitm.Value = s Then
pvt.PageFields(1).CurrentPage = pitm.Value
Exit For
End If
Next
End If
Next
End If
Next

End Sub

--
Regards,
Tom Ogilvy


"Sharon" wrote:

Hi - I have code that automatically selects an item from a series of pivot
page fields when the user clicks on a button. However, if the item does not
exist in the page field dropdown, the code crashes and I don't know to trap
that error and tell the code to move on to the next thing? Any help would be
very, very gratefully received!!

This is sort of a repost and I don't think I explained the problem very well
last time.

Thanks
--
Sharon

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
Looping page fields in pivot table [email protected] Excel Programming 1 March 14th 06 12:46 AM
Pivot Table Page fields Ajit Excel Discussion (Misc queries) 1 October 12th 05 05:49 PM
Pivot Table page fields Chad W. Excel Discussion (Misc queries) 1 July 27th 05 04:27 PM
How do I set up filter for page fields in pivot table? Mitsycat Excel Discussion (Misc queries) 3 May 6th 05 10:27 PM
Pivot Table Page Fields Andy Excel Discussion (Misc queries) 1 December 17th 04 05:25 PM


All times are GMT +1. The time now is 06:53 AM.

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"