pivot managment through VBA

C

catrrmg

hi all
could someone give me a hand with this piece of code which I can't get to
work for me:
indPlan = Sheets("pivot").Range("L46").Value
Select Case indPlan
Case indPlan <= 3
tptPlanMonths.PivotFields("quarter").PivotItems(1).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(2).Visible = False
tptPlanMonths.PivotFields("quarter").PivotItems(3).Visible = False
tptPlanMonths.PivotFields("quarter").PivotItems(4).Visible = False
Case indPlan >= 4 & indPlan <= 6
tptPlanMonths.PivotFields("quarter").PivotItems(1).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(2).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(3).Visible = False
tptPlanMonths.PivotFields("quarter").PivotItems(4).Visible = False
Case indPlan >= 7 & indPlan <= 9
tptPlanMonths.PivotFields("quarter").PivotItems(1).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(2).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(3).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(4).Visible = False
Case indPlan >= 10 & indPlan <= 12
tptPlanMonths.PivotFields("quarter").PivotItems(1).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(2).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(3).Visible = True
tptPlanMonths.PivotFields("quarter").PivotItems(4).Visible = True
End Select
thanks a lot in advance!
 
B

barnabel

What is it doing? I think pivotitems might be 0 based rather than 1 based.
But why not use the names instead?

tptPlanMonths.PivotFields("quarter").PivotItems("1").Visible =
True
tptPlanMonths.PivotFields("quarter").PivotItems("2").Visible =
False
or
tptPlanMonths.PivotFields("quarter").PivotItems("1ST").Visible
= True
tptPlanMonths.PivotFields("quarter").PivotItems("2ND").Visible
= False


whatever the values are for the field.
 
C

catrrmg

hi
the idea is whenever a user selects an item (in this case annual quarters)
from a drop down list, the result through Sheets("pivot").Range("L46").Value
is processed by the code, which in case the user selects let's say 2 should
show only the first two quarters and so on... unfortunatelly the case
statement I'm using just goes through the code to the end sub not finding any
result to match... your help will be much appreciated...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top