Pivot Table Zero Value

G

Guest

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?
 
G

Guest

2 suggestions would be

a) Can't you untick the £0 value in the pivot table list for that field
b) Can't you use an ordinary filter


HTH
 
G

Guest

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
 
D

Dave Peterson

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.
 
D

Debra Dalgleish

Hi Jason,

Are you using Excel 2002 or Excel 2003, or an earlier version?

Debra
 
G

Guest

Hi Debra,

I'm sorry I forgot to include the version. I'm using Excel 2003.

Thanks again,
JAson
 
G

Guest

Hi Dave,

Thanks for the input. I tried it both with the pivot table sheet active,
and inactive. Either way, I was receiving the error messages. Thanks though!

Jason
 
G

Guest

Hi Debra,

I just realized something else with which I'm having an issue. The column
headings used in the template can change depending upon who uses them. (Each
user selects his/her country from a drop-down, and based on the selection,
certain headings show. The headings that change are always in the data field
of the table. i've noticed that when they change, they drop out of the
table. Is there any way to reference the column by it's location rather than
it's name? Or is there any way to keep them from dropping from the table
when they change?

Thanks again,
Jason
 
D

Debra Dalgleish

If the information is summarized on another sheet, do you need to use a
pivot table? Maybe an AutoFilter on the summary sheet would be a better
tool for this.

To maintain all the item headings, you could check the 'show items with
no data' box in the Data Field Settings dialog box.
 
G

Guest

The information is summarized, but I was hoping to have it in a format as
below. The input sheet has one row for each person, and the various services
are in columns. So, a check in C2 returns John Smith U.S. Return, D2 is John
Smith State Return, etc. The next row would be for John Doe, and so on. I
liked the way the pivot table put the info in rows like that, whereas my
summary sheet shows amounts (pulled from a table depending upon which country
performs the service) in the same format as the input page. Is that possible
without a pivot table?

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

THanks again,
Jason
 
D

Debra Dalgleish

A pivot table would be the easiest way to show the return types in a
column. But the name and ID number will only show once, not repeated for
each row.

I assumed the sample showed how your source data was arranged. If this
is how the pivot table is arranged, the HideZero macro won't work. If
you hide a Data item, it would hide it for all names. If you run a macro
that simply hides the rows that contain a zero total, it could hide rows
that contain the Name and ID, leaving many rows unidentified.
 
G

Guest

Well, again, thanks very much for the help. I guess the pivot table is the
best bet then.

Thanks again,
Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top