bremen_
09-15-2016, 04:28 AM
Hi everyone!
I have an pivottable with pivofields ("Year").
Via a UserForm I chose the desired period using 2 Comboboxes: Combobox1 (from) and Combobox2 (to).
Depending on the selected period, e.g. from 2011 to 2013, i want to select all of the years in the pivot table in that period (2011, 2012, 2013).
I came up with a code, it makes something, but not that what i want... Right now the code selects the pivoitems 2,3,4 (but manually, with fix values in the code) but i want it to select them depending on the variable in the combobox.
Sub pivot_item_jahr()
Dim oPI As PivotItem
Dim i As Integer
For Each oPI In ActiveSheet.PivotTables("PivotTable2").PivotFields("Year").PivotItems
For i = 2 To 4
ActiveSheet.PivotTables("PivotTable2").PivotFields("Year").PivotItems(i).Visible = True
Next i
oPI.Visible = False
Next oPI
End Sub
Thanks a lot for any help!
I have an pivottable with pivofields ("Year").
Via a UserForm I chose the desired period using 2 Comboboxes: Combobox1 (from) and Combobox2 (to).
Depending on the selected period, e.g. from 2011 to 2013, i want to select all of the years in the pivot table in that period (2011, 2012, 2013).
I came up with a code, it makes something, but not that what i want... Right now the code selects the pivoitems 2,3,4 (but manually, with fix values in the code) but i want it to select them depending on the variable in the combobox.
Sub pivot_item_jahr()
Dim oPI As PivotItem
Dim i As Integer
For Each oPI In ActiveSheet.PivotTables("PivotTable2").PivotFields("Year").PivotItems
For i = 2 To 4
ActiveSheet.PivotTables("PivotTable2").PivotFields("Year").PivotItems(i).Visible = True
Next i
oPI.Visible = False
Next oPI
End Sub
Thanks a lot for any help!