View Single Post
  #5   Report Post  
Dave Peterson
 
Posts: n/a
Default

PMFJI,

But I tried your code and with a minor tweak, it worked ok:

I changed this line:
str = Cells(r, 1).Value
to
str = Sheets("pivot").Cells(r, 1).Value

But if you had the pivot sheet active, then this suggestion isn't the fix.



jcliquidtension wrote:

Hi Debra,

First, thanks in advance for your help. I've read many of your posts, and
they're very informative. However, I still cannot get this pivot table -
zero value thing to work! The macro I tried is below. I changed the sheet
reference to my sheet, and I also changed the column and row references. Row
- Name; Column - Data. When those references did not work, I tried others
(total, amount, etc.), but still cannot get it to work. The best I could do
was to get past the reference errors, and then it just runs continuously.

Again, thanks in advance for your help!
Jason

Sub HideZeroRowTotals()
'hide rows that contain zero totals
Dim r As Integer
Dim rTop As Integer
Dim i As Integer
Dim pt As PivotTable
Dim pf As PivotField
Dim df As PivotField
Dim pi As PivotItem
Dim pd As Range
Dim str As String
Set pt = Sheets("Pivot").PivotTables(1)
Set df = pt.PivotFields("Amount") 'data field
Set pf = pt.PivotFields("Code") 'row field
rTop = 4 'number of rows before data starts
For Each pi In pf.PivotItems
On Error Resume Next
pi.Visible = True
Next pi
i = pf.PivotItems.Count + rTop
For r = i To rTop - 1 Step -1
On Error Resume Next
str = Cells(r, 1).Value
Set pd = pt.GetPivotData(df.Value, pf.Value, str)
If pd.Value = 0 Then
pf.PivotItems(str).Visible = False
End If
Next r

End Sub

"Debra Dalgleish" wrote:

Which macro are you using, and what version of Excel do you have?

jcliquidtension wrote:
Hi,

I've seen many questions on this subject, but none of the solutions seem to
work for me. I have a pivot table that summarizes billing amounts for 20-25
different data items. Also, the rows have two fields. For Example:

Name I.D. Data
Total
John Smith 7756 U.S. Tax Return $800
John Smith 7756 State Tax Return $250
John Smith 7756 Add'l State Return $0
John Doe 8876 U.S. Tax Return $800
John Doe 8876 State Tax Return $0
John Doe 8876 Add'l State Return $0

I'd like to hide the rows with a zero value. I tried coding the summary
worksheet (from which the pivot table pulls) to return "" rather than 0 if
the service was not performed. I then unchecked "show blank items," and
unchecked the "show blank as...." and "show zero as...." items.

I also tried Debra D's macro, but when I run it, it seems to run
continuously and doens't hide anything. (I have to escape from it to stop
it.)

All I need to do is hide the rows with zero values. Is this possible?



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html



--

Dave Peterson