ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   problem with macro for pivot tables (https://www.excelbanter.com/excel-programming/303533-problem-macro-pivot-tables.html)

Hans

problem with macro for pivot tables
 
Hi All,

Im trying to write a macro that makes a period visible in
a number of Pivottables (all in one workbook). The period
is mentioned in the cell with the name period.

I have come up with the macro mentioned below, but it does
not work with the 'bPeriodNew' in the following line:
PT.PivotFields("period").PivotItem(bPeriodNew).Vis ible =
True

However, when I change 'bPeriodNew' to, for example, '"2"'
in this line, it works perfectly well.

I checked the value of the line:
bPeriodNew = Range("period").Value
in my direct screen and it gives a correct value. Yet the
macro does not work.

Any idea what I am doing wrong?

Kind regards,
Hans


Sub ChangePeriodPivot

Dim bPeriodNew As Byte
Dim PT As PivotTable
Dim Sh1 As Sheets
Dim wk As Worksheet

bPeriodNew = Range("period").Value
Set sh1 = Worksheets(Array[number of sheets])

For Each wk In Sh1
For Each PT In wk.PivotTables
PT.PivotFields("period").PivotItem(bPeriodNew).Vis ible
= True
Next PT
Next wk

End Sub



All times are GMT +1. The time now is 03:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com