poisonbrandi
New Member
- Joined
- Sep 7, 2015
- Messages
- 1
Hi,
I am relatively new to VBA and I am trying to write up a code to be able to filter a pivot table using checkboxes:
Sub RentCheck()
If Sheets("Dashboard").CheckBoxes("RentCheck").Value = xlOff Then
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY15")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = False
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY16")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = False
Set pt = Nothing
End If
If Sheets("Dashboard").CheckBoxes("RentCheck").Value = xlOn Then
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY15")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = True
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY16")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = True
Set pt = Nothing
End If
End Sub
I keep on getting that 1004 error though and the help option is not very helpful, can someone please explain what I have done wrong?
I am relatively new to VBA and I am trying to write up a code to be able to filter a pivot table using checkboxes:
Sub RentCheck()
If Sheets("Dashboard").CheckBoxes("RentCheck").Value = xlOff Then
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY15")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = False
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY16")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = False
Set pt = Nothing
End If
If Sheets("Dashboard").CheckBoxes("RentCheck").Value = xlOn Then
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY15")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = True
Set pt = Sheets("Pivots").PivotTables("PercentofRevFY16")
pt.PivotFields("[Booking].[CHARGE]").PivotItems("[Booking].[CHARGE].&[Rent]").Visible = True
Set pt = Nothing
End If
End Sub
I keep on getting that 1004 error though and the help option is not very helpful, can someone please explain what I have done wrong?