Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default delete selection in pivotcolumn

Hi all,

I am looking for code that clears all selections in a pivotfield. Pivottable compares values of current and previous yyear with budget. My goal is to always have only two years. namely the current and previous.
So far I have created:

sub twoyears()
curyear = Range("curyear").Value ' a cellreference having the value of this year
prevyear = Range("prevyear").Value ' a cellreference with value of 1 less

Sheets("Tur. YTD").Select
ActiveSheet.PivotTables("Tur. YTD").PivotFields("Region").ClearAllFilters
ActiveSheet.PivotTables("Tur. YTD").PivotFields("Region").CurrentPage = "All"
With ActiveSheet.PivotTables("Tur. YTD").PivotFields("Month")
.PivotItems("(blank)").Visible = False
End With

'this is he piece of code where i'm strugging with. when the for each loop has run three times, the column has no values and i get an error.
On Error Resume Next
For Each item In ActiveSheet.PivotTables("Tur. YTD").PivotFields("Year").PivotItems
item.Visible = False
Next
With ActiveSheet.PivotTables("Tur. YTD").PivotFields("Year")
.PivotItems(curyear).Visible = True
.PivotItems(prevyear).Visible = True
.PivotItems("budget").Visible = True
End With

end sub

Of course the 'resume next' solves the problem, but i don't think this is very elegant.
so my question is: what is the easiest way to clear selections in a pivotfieldcolumn

any help is greatly appreciated

greets,

sybolt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default delete selection in pivotcolumn

hi sybolt,

Sub Macro1()
Dim criteria, pi As PivotItem
criteria = Array("curyear", "prevyear", "budget")
Application.ScreenUpdating = False
With ActiveSheet.PivotTables(1).PivotFields(1)
.ClearAllFilters
For Each pi In .PivotItems
If Not IsError(Application.Match(pi, criteria, 0)) Then
pi.Visible = True
Else
pi.Visible = False
End If
Next
End With
Application.ScreenUpdating = True
End Sub

--
isabelle

--
isabelle


Le 2012-11-29 05:26, a écrit :
Of course the 'resume next' solves the problem, but i don't think this is very elegant.
so my question is: what is the easiest way to clear selections in a pivotfieldcolumn

any help is greatly appreciated

greets,

sybolt


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default delete selection in pivotcolumn

On Thursday, November 29, 2012 11:26:53 AM UTC+1, wrote:
Hi all,



I am looking for code that clears all selections in a pivotfield. Pivottable compares values of current and previous yyear with budget. My goal is to always have only two years. namely the current and previous.

So far I have created:



sub twoyears()

curyear = Range("curyear").Value ' a cellreference having the value of this year

prevyear = Range("prevyear").Value ' a cellreference with value of 1 less



Sheets("Tur. YTD").Select

ActiveSheet.PivotTables("Tur. YTD").PivotFields("Region").ClearAllFilters

ActiveSheet.PivotTables("Tur. YTD").PivotFields("Region").CurrentPage = "All"

With ActiveSheet.PivotTables("Tur. YTD").PivotFields("Month")

.PivotItems("(blank)").Visible = False

End With



'this is he piece of code where i'm strugging with. when the for each loop has run three times, the column has no values and i get an error.

On Error Resume Next

For Each item In ActiveSheet.PivotTables("Tur. YTD").PivotFields("Year").PivotItems

item.Visible = False

Next

With ActiveSheet.PivotTables("Tur. YTD").PivotFields("Year")

.PivotItems(curyear).Visible = True

.PivotItems(prevyear).Visible = True

.PivotItems("budget").Visible = True

End With



end sub



Of course the 'resume next' solves the problem, but i don't think this is very elegant.

so my question is: what is the easiest way to clear selections in a pivotfieldcolumn



any help is greatly appreciated



greets,



sybolt


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default delete selection in pivotcolumn

Hi Isabella,

Thanks ever so much for your reply. I always seem to forget about arrays.
With a few adjustments I got the code running as I wanted.

The code is quicker and 'plus stabile'

Merci,

Sybolt
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
XL2007, Selection.Delete deletes more than the selection xlrotor[_2_] Excel Programming 5 March 3rd 08 11:36 PM
delete a selection flirtacious Charts and Charting in Excel 2 November 25th 07 01:57 PM
Problem of selection.delete Radhakrishna k.v.n.r[_2_] Excel Worksheet Functions 7 October 27th 07 11:50 AM
Copy Selection - Paste Selection - Delete Selection Uninvisible Excel Programming 2 October 25th 07 01:31 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM


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

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"