title: filter out zeros in pivot table using vba codes
body: <p>I have vba codes that help me to create pivot tables but now I encounter entries that have 0 values, showing as blank on pivot table but I would like to modify my codes so that I can filter out 0 values. In another word, I would like to make pivotitem to not show if values are 0 on the right side.</p>
  
  <p>Please see picture for desire results. When I run my codes, there is no error, it seems like nothing happened.</p>
  
  <pre><code>'filter out zero
      Dim ws1 As Worksheet
      Set ws1 = Worksheets("PivotTable")
  
      Dim pf2 As PivotField
      Set pf2 = Pvt.PivotFields("Price Range")
  
      Dim pi2 As PivotItem
      For Each pi2 In pf2.PivotItems
          pi2.Visible = Len(ws1.Range(pi2.DataRange.Address)) &gt; 0
      Next
  
  End Sub
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/TyNoS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TyNoS.png" alt="enter image description here"></a></p>