Pivot Tables: Hide detail for a RowField via code: Get an Error?

  • Thread starter Kevin McCartney
  • Start date
K

Kevin McCartney

Hi TWIMC

I get the following error '1004: unable to set the ShowDetail property of
the Range class' when I try to hide the details for a particular RowField in
my pivot table. The line of code that causes the error is ws.Cells(rge.Row,
rge.Column).ShowDetail = False (4th from bottom), anway I'm not sure why
because if I record a macro in Excel when I do it manully I get the code.

Selection.ShowDetail = False

Thus I tried to implement it programitically and look at each RowField one
by one and if for that RowField in the same column but in row 1, if the cell
value was HIDE I wanted to set the RowField to ShowDetail = False

This is the code I used:

For Each pfd In pt.RowFields
' For any fields that are used in the row area and need
to be set to HIDE DETAIL,
For Each rge In pt.RowRange
' find cells in row 1 where the value is HIDE ans set
accordingly.
If pfd.Name = ws.Cells(rge.Row, rge.Column).Value And
ws.Cells(1, rge.Column).Value = "HIDE" Then


ws.Cells(rge.Row, rge.Column).ShowDetail = False


End If
Next rge
Next pfd

The error message that I get is '1004: unable to set the ShowDetail property
of the Range class'

not sure and I haven't bee able to figure it out yet but I'm hoping someone
out there can.

Any help, very much appreciated.

TIA
KM
 

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