Hi,
I am struggling with a macro to set multiple pivot items based on multiple cells. I have tried different codes but they don't work as they should be.
In this case, I would like the macro to set the months based on cells "'Validatie'!AQ2" and "'Validatie'!AQ3". These cells contain numeric values (month numbers).
For example, the cells contain the values 10 (AQ2) and 9 (AQ3). I want the macro to only select the values 9 and 10 as Pivot item within the pivot field "Maand".
The code that I have (it outputs the value fron AQ2):
Thanks for your help!
I am struggling with a macro to set multiple pivot items based on multiple cells. I have tried different codes but they don't work as they should be.
In this case, I would like the macro to set the months based on cells "'Validatie'!AQ2" and "'Validatie'!AQ3". These cells contain numeric values (month numbers).
For example, the cells contain the values 10 (AQ2) and 9 (AQ3). I want the macro to only select the values 9 and 10 as Pivot item within the pivot field "Maand".
The code that I have (it outputs the value fron AQ2):
Code:
Sub filter_mom()
Dim item As String, it As PivotItem
item = Range("'Validatie'!AQ2, 'Validatie'!AQ3").Value
ActiveSheet.PivotTables("Draaitabel1").PivotFields("Maand"). _
ClearAllFilters
For Each it In ActiveSheet.PivotTables("Draaitabel1").PivotFields("Maand").PivotItems
If item = it.Name Then
it.Visible = True
Else
it.Visible = False
End If
Next it
End Sub
Thanks for your help!