T
Thomas V
Hi,
I've run into a bit of a pickle with a VBA script.
The script sets formatting on PivotItems by cycling through the
VisibleItems collection. This works fine until I add a page field.
I've figured out that the Visible property of the PivotItem stays True
even though the item may be hidden by the selection on the page field.
The collection is therefore not that useful to me since it will cause
errors with any calls to get a range for any PivotItem hidden from
view by the page field. How can I get around this?
Below is an excerpt of the script in question:
==================================================
01 Dim pvtItems As PivotItems, pvtItem As PivotItem
02 Set pvtItems = pvtTable.PivotFields(myRow).VisibleItems
03 For Each pvtItem In pvtItems
04 pvtItem.LabelRange.Select
05
06 With Selection
07 .Borders.LineStyle = xlNone
08 .Borders(xlEdgeTop).LineStyle = xlContinuous
09 .Borders(xlEdgeTop).Weight = xlHairline
10 .Borders(xlEdgeTop).ColorIndex = xlAutomatic
11 .Borders(xlEdgeBottom).LineStyle = xlContinuous
12 .Borders(xlEdgeBottom).Weight = xlHairline
13 .Borders(xlEdgeBottom).ColorIndex = xlAutomatic
14 End With
15 Next pvtItem
==================================================
The above script will fail on line 04 as soon as it hits an PivotItem
which is hidden from view by any other selections made in the pivot
table (e.g. on the page field).
Your help is greatly appreciated.
- Thomas
I've run into a bit of a pickle with a VBA script.
The script sets formatting on PivotItems by cycling through the
VisibleItems collection. This works fine until I add a page field.
I've figured out that the Visible property of the PivotItem stays True
even though the item may be hidden by the selection on the page field.
The collection is therefore not that useful to me since it will cause
errors with any calls to get a range for any PivotItem hidden from
view by the page field. How can I get around this?
Below is an excerpt of the script in question:
==================================================
01 Dim pvtItems As PivotItems, pvtItem As PivotItem
02 Set pvtItems = pvtTable.PivotFields(myRow).VisibleItems
03 For Each pvtItem In pvtItems
04 pvtItem.LabelRange.Select
05
06 With Selection
07 .Borders.LineStyle = xlNone
08 .Borders(xlEdgeTop).LineStyle = xlContinuous
09 .Borders(xlEdgeTop).Weight = xlHairline
10 .Borders(xlEdgeTop).ColorIndex = xlAutomatic
11 .Borders(xlEdgeBottom).LineStyle = xlContinuous
12 .Borders(xlEdgeBottom).Weight = xlHairline
13 .Borders(xlEdgeBottom).ColorIndex = xlAutomatic
14 End With
15 Next pvtItem
==================================================
The above script will fail on line 04 as soon as it hits an PivotItem
which is hidden from view by any other selections made in the pivot
table (e.g. on the page field).
Your help is greatly appreciated.
- Thomas