I am trying to create a pivot table that would show all the months in a year even if it doesn't have any data then later on this will be a basis for my charts. So I went I click on the "show items with no data" in field settings layout & print. However, excel automatically shows less than a specific date and greater than a specific date. e.g. <30/06/2013 and >23/06/2014. I was trying to get rid of those by naming a specific cell that contains <30/06/2013 as min and >23/06/2014 as max. Then I am trying to create a vba that would automatically de-select those by looking into those named cell. However, there is always an error.
I am just a beginner in vba so I would be grateful if you could help me. Thanks.
Below is my code;
Dim min As String
Dim max As String
Dim pvtItem As PivotItem
min = Range("min").Value
max = Range("max").Value
With ActiveSheet.PivotTables("PivotTable7").PivotFields("Years")
.ShowAllItems = True
For Each pvtItem In .PivotItems
pvtItem.Visible = pvtItem.Name = "min"
pvtItem.Visible = (pvtItem.Name = max)
Next
End With
I am just a beginner in vba so I would be grateful if you could help me. Thanks.
Below is my code;
Dim min As String
Dim max As String
Dim pvtItem As PivotItem
min = Range("min").Value
max = Range("max").Value
With ActiveSheet.PivotTables("PivotTable7").PivotFields("Years")
.ShowAllItems = True
For Each pvtItem In .PivotItems
pvtItem.Visible = pvtItem.Name = "min"
pvtItem.Visible = (pvtItem.Name = max)
Next
End With
Last edited: