PC Review


Reply
Thread Tools Rate Thread

Delete Blank Rows when Pivot Table included on sheet

 
 
Joyce
Guest
Posts: n/a
 
      21st Mar 2010
Hi,

I've run code to delete blank rows which works fine. That is, it works fine
until I'm deleting blank rows on a sheet which also contains a few pivot
tables.

I encounter an error message regarding not being able to change pivot table.

Here is my code: Thanks!

Dim x As Long

With ActiveSheet
For x = .Cells.SpecialCells(xlCellTypeLastCell).Row _
To 1 Step -1

If WorksheetFunction.CountA(.Rows(x)) = 0 Then
ActiveSheet.Rows(x).Delete
End If

Next
End With
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      22nd Mar 2010
You can't delete or add rows to a Pivot Table. Delete all blanks before you
build the Pivot Table (I assume you are building the table with code, right).
Or, in your Pivot Table you will see some down arrows, click any one and if
there are blanks in there you'll see (blank) with a small check box in front
of it. Un-check the box and that will eliminate the blanks. Then, turn on
the macro recorder and do the same thing and turn off the recorder. Look at
the resulting code. Copy/paste that code into the appropriate place in your
code-sequence, and Excel will automatically do this for you next time
(eliminate blanks). You may have to play with the positioning of the code a
bit to get it working right, but just keep at it and you'll get it.

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Joyce" wrote:

> Hi,
>
> I've run code to delete blank rows which works fine. That is, it works fine
> until I'm deleting blank rows on a sheet which also contains a few pivot
> tables.
>
> I encounter an error message regarding not being able to change pivot table.
>
> Here is my code: Thanks!
>
> Dim x As Long
>
> With ActiveSheet
> For x = .Cells.SpecialCells(xlCellTypeLastCell).Row _
> To 1 Step -1
>
> If WorksheetFunction.CountA(.Rows(x)) = 0 Then
> ActiveSheet.Rows(x).Delete
> End If
>
> Next
> End With

 
Reply With Quote
 
Joyce
Guest
Posts: n/a
 
      22nd Mar 2010
Hi Ryan,
Thanks so much for your response. Here is my problem in more detail. I
have a report that contains many pivot tables that are positioned vertically
one beneath the other. There are report headings and information above the
pivot tables as well.

I don't want to overwrite the text between the pivot tables as the pivot may
expand. At the moment, the only solution I can see is to add a bunch of rows
under each pivot table so that refreshing them based on updated data and
different Page Field selections won't overwrite anything.

Unfortunately, though, it means I end up with many, many rows very often
that remain beneath various pivot tables. I'd like to have an easy way to
remove these. I had used placeholders on rows I don't want removed and run
my code to delete blank rows that I've used often in other reports that don't
contains pivots, but get a runtime error 1004 when try to run it in one that
does.

Is there a way to add something that says, in essence, "ignore pivot
tables"?

Any suggestions are very appreciated.

"ryguy7272" wrote:

> You can't delete or add rows to a Pivot Table. Delete all blanks before you
> build the Pivot Table (I assume you are building the table with code, right).
> Or, in your Pivot Table you will see some down arrows, click any one and if
> there are blanks in there you'll see (blank) with a small check box in front
> of it. Un-check the box and that will eliminate the blanks. Then, turn on
> the macro recorder and do the same thing and turn off the recorder. Look at
> the resulting code. Copy/paste that code into the appropriate place in your
> code-sequence, and Excel will automatically do this for you next time
> (eliminate blanks). You may have to play with the positioning of the code a
> bit to get it working right, but just keep at it and you'll get it.
>
> --
> Ryan---
> If this information was helpful, please indicate this by clicking ''Yes''.
>
>
> "Joyce" wrote:
>
> > Hi,
> >
> > I've run code to delete blank rows which works fine. That is, it works fine
> > until I'm deleting blank rows on a sheet which also contains a few pivot
> > tables.
> >
> > I encounter an error message regarding not being able to change pivot table.
> >
> > Here is my code: Thanks!
> >
> > Dim x As Long
> >
> > With ActiveSheet
> > For x = .Cells.SpecialCells(xlCellTypeLastCell).Row _
> > To 1 Step -1
> >
> > If WorksheetFunction.CountA(.Rows(x)) = 0 Then
> > ActiveSheet.Rows(x).Delete
> > End If
> >
> > Next
> > End With

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      23rd Mar 2010
Sounds somewhat complex, but equally interesting. I have some free time in
the next day or so to look at this. If you send me a before and after
example, I'll try to reply back with a solution within the next day or so.
Thanks!!
(E-Mail Removed)

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Joyce" wrote:

> Hi Ryan,
> Thanks so much for your response. Here is my problem in more detail. I
> have a report that contains many pivot tables that are positioned vertically
> one beneath the other. There are report headings and information above the
> pivot tables as well.
>
> I don't want to overwrite the text between the pivot tables as the pivot may
> expand. At the moment, the only solution I can see is to add a bunch of rows
> under each pivot table so that refreshing them based on updated data and
> different Page Field selections won't overwrite anything.
>
> Unfortunately, though, it means I end up with many, many rows very often
> that remain beneath various pivot tables. I'd like to have an easy way to
> remove these. I had used placeholders on rows I don't want removed and run
> my code to delete blank rows that I've used often in other reports that don't
> contains pivots, but get a runtime error 1004 when try to run it in one that
> does.
>
> Is there a way to add something that says, in essence, "ignore pivot
> tables"?
>
> Any suggestions are very appreciated.
>
> "ryguy7272" wrote:
>
> > You can't delete or add rows to a Pivot Table. Delete all blanks before you
> > build the Pivot Table (I assume you are building the table with code, right).
> > Or, in your Pivot Table you will see some down arrows, click any one and if
> > there are blanks in there you'll see (blank) with a small check box in front
> > of it. Un-check the box and that will eliminate the blanks. Then, turn on
> > the macro recorder and do the same thing and turn off the recorder. Look at
> > the resulting code. Copy/paste that code into the appropriate place in your
> > code-sequence, and Excel will automatically do this for you next time
> > (eliminate blanks). You may have to play with the positioning of the code a
> > bit to get it working right, but just keep at it and you'll get it.
> >
> > --
> > Ryan---
> > If this information was helpful, please indicate this by clicking ''Yes''.
> >
> >
> > "Joyce" wrote:
> >
> > > Hi,
> > >
> > > I've run code to delete blank rows which works fine. That is, it works fine
> > > until I'm deleting blank rows on a sheet which also contains a few pivot
> > > tables.
> > >
> > > I encounter an error message regarding not being able to change pivot table.
> > >
> > > Here is my code: Thanks!
> > >
> > > Dim x As Long
> > >
> > > With ActiveSheet
> > > For x = .Cells.SpecialCells(xlCellTypeLastCell).Row _
> > > To 1 Step -1
> > >
> > > If WorksheetFunction.CountA(.Rows(x)) = 0 Then
> > > ActiveSheet.Rows(x).Delete
> > > End If
> > >
> > > Next
> > > End With

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table - with blank rows ColG Microsoft Excel Misc 6 18th Mar 2009 04:12 PM
Pivot Table blank rows Mostachon Microsoft Excel Misc 1 5th Sep 2008 06:36 PM
Pivot Table with Blank Rows - HELP =?Utf-8?B?U2FuZGk=?= Microsoft Excel Misc 2 4th Aug 2006 08:03 PM
Delete all blank rows in sheet? Gregg Hill Microsoft Excel Discussion 6 21st Aug 2004 10:59 PM
How to delete all blank rows in a sheet? Gregg Hill Microsoft Excel Discussion 8 6th Jan 2004 05:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:59 PM.