PC Review


Reply
Thread Tools Rate Thread

code to delete all rows beneath and columns right of pivot table

 
 
klysell
Guest
Posts: n/a
 
      7th Feb 2008
Hi,

My macro parses codes on my summary sheet into separate pivot tables
contained on separate worksheets thereby using these individual codes as page
fields for these pivot tables. Because I have too much data, I had to create
a forumula driven variance column lying outside of the pivot table (else the
code that creates the pivot table crashes). However, now my print macros
don't work because for some reason, the print preview function reads all the
variance formulas (although blank) going to down to, say, row 2000. Instead
of nicely fitting the pivot table onto one, two or three pages, I have 65+
blank pages due to the formulas running down past my pivot table (these
variance formulas show a blank i.e. "" in cells below my pivot tables).

Therefore, I either: 1) need to create a print area for just the pivot
table; or 2) delete all rows beneath the macro-generated pivot table
(starting row not known in advance).

Any help would be appreciate.

Cheers,

Kent Lysell
IBM Consultant
Ottawa, Ontario
 
Reply With Quote
 
 
 
 
Bernie Deitrick
Guest
Posts: n/a
 
      7th Feb 2008
Kent,

1)
To set the print area to just the pivot table, use code like

ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
ActiveSheet.PageSetup.PrintArea = Selection.Address

2)

Dim myR As Range
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
Set myR = Selection

Range(myR(myR.Cells.Count)(2), Cells(Rows.Count, 1)).EntireRow.Delete
Range(myR(myR.Cells.Count)(1, 2), Cells(1, Columns.Count)).EntireColumn.Delete


If the sheet isn't the activesheet, use Worksheets("Sheetname").Activate first, in either example.
And, of course, you will need to change the name of the pivottable. If each sheet has only one, then

ActiveSheet.PivotTables(1).PivotSelect "", xlDataAndLabel, True

should work.

HTH,
Bernie
MS Excel MVP


"klysell" <(E-Mail Removed)> wrote in message
news:8C41042A-F785-4FD8-8C7D-(E-Mail Removed)...
> Hi,
>
> My macro parses codes on my summary sheet into separate pivot tables
> contained on separate worksheets thereby using these individual codes as page
> fields for these pivot tables. Because I have too much data, I had to create
> a forumula driven variance column lying outside of the pivot table (else the
> code that creates the pivot table crashes). However, now my print macros
> don't work because for some reason, the print preview function reads all the
> variance formulas (although blank) going to down to, say, row 2000. Instead
> of nicely fitting the pivot table onto one, two or three pages, I have 65+
> blank pages due to the formulas running down past my pivot table (these
> variance formulas show a blank i.e. "" in cells below my pivot tables).
>
> Therefore, I either: 1) need to create a print area for just the pivot
> table; or 2) delete all rows beneath the macro-generated pivot table
> (starting row not known in advance).
>
> Any help would be appreciate.
>
> Cheers,
>
> Kent Lysell
> IBM Consultant
> Ottawa, Ontario



 
Reply With Quote
 
klysell
Guest
Posts: n/a
 
      7th Feb 2008
Thanks, that's great Bernie. One more thing: I need to select all leading
rows above the pivot table (rows 1 to 5) as well as the pivot table (starting
on row 12) since the leading rows contain formula-driven titles. I don't know
the name the sheet beforehand, so I'll have to create a name range on the
master pivot table from which the macro copies to create the new pivot
table(s). - K.
--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Bernie Deitrick" wrote:

> Kent,
>
> 1)
> To set the print area to just the pivot table, use code like
>
> ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
> ActiveSheet.PageSetup.PrintArea = Selection.Address
>
> 2)
>
> Dim myR As Range
> ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
> Set myR = Selection
>
> Range(myR(myR.Cells.Count)(2), Cells(Rows.Count, 1)).EntireRow.Delete
> Range(myR(myR.Cells.Count)(1, 2), Cells(1, Columns.Count)).EntireColumn.Delete
>
>
> If the sheet isn't the activesheet, use Worksheets("Sheetname").Activate first, in either example.
> And, of course, you will need to change the name of the pivottable. If each sheet has only one, then
>
> ActiveSheet.PivotTables(1).PivotSelect "", xlDataAndLabel, True
>
> should work.
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "klysell" <(E-Mail Removed)> wrote in message
> news:8C41042A-F785-4FD8-8C7D-(E-Mail Removed)...
> > Hi,
> >
> > My macro parses codes on my summary sheet into separate pivot tables
> > contained on separate worksheets thereby using these individual codes as page
> > fields for these pivot tables. Because I have too much data, I had to create
> > a forumula driven variance column lying outside of the pivot table (else the
> > code that creates the pivot table crashes). However, now my print macros
> > don't work because for some reason, the print preview function reads all the
> > variance formulas (although blank) going to down to, say, row 2000. Instead
> > of nicely fitting the pivot table onto one, two or three pages, I have 65+
> > blank pages due to the formulas running down past my pivot table (these
> > variance formulas show a blank i.e. "" in cells below my pivot tables).
> >
> > Therefore, I either: 1) need to create a print area for just the pivot
> > table; or 2) delete all rows beneath the macro-generated pivot table
> > (starting row not known in advance).
> >
> > Any help would be appreciate.
> >
> > Cheers,
> >
> > Kent Lysell
> > IBM Consultant
> > Ottawa, Ontario

>
>
>

 
Reply With Quote
 
klysell
Guest
Posts: n/a
 
      7th Feb 2008
Bernie,

I tried to second method to delete rows below my macro-generate pivot table
and got an error message "Method 'Range' of Object '_Worksheet' failed". Here
is the code that you gave me in the context of my code:

Sheets("PIV_SOF").Visible = True
Application.Goto "SOF_BACK_TO_SUMMARY"
Worksheets("PIV_SOF").Copy _
After:=Worksheets(Worksheets.Count)
Sheets("PIV_SOF").Visible = False

Set Sh = ActiveSheet
Sh.Name = Target & "-Source of Funds"
Sh.Tab.ColorIndex = 33
For Each pt In Sh.PivotTables
With pt
With .PivotFields("RC")
For Each pi In .PivotItems
If LCase(pi.Value) = LCase(Target.Value) Then
.CurrentPage = pi.Value

Dim myR As Range
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel,
True
Set myR = Selection

Range(myR(myR.Cells.Count)(2), Cells(Rows.Count, 1)).EntireRow.Delete
Range(myR(myR.Cells.Count)(1, 2), Cells(1,
Columns.Count)).EntireColumn.Delete

Call Formatting_SOF
'
'
'
'
Any suggestions?
Thanks.

--
Kent Lysell
Financial Consultant
Ottawa, Ontario
W: 613.948-9557


"Bernie Deitrick" wrote:

> Kent,
>
> 1)
> To set the print area to just the pivot table, use code like
>
> ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
> ActiveSheet.PageSetup.PrintArea = Selection.Address
>
> 2)
>
> Dim myR As Range
> ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
> Set myR = Selection
>
> Range(myR(myR.Cells.Count)(2), Cells(Rows.Count, 1)).EntireRow.Delete
> Range(myR(myR.Cells.Count)(1, 2), Cells(1, Columns.Count)).EntireColumn.Delete
>
>
> If the sheet isn't the activesheet, use Worksheets("Sheetname").Activate first, in either example.
> And, of course, you will need to change the name of the pivottable. If each sheet has only one, then
>
> ActiveSheet.PivotTables(1).PivotSelect "", xlDataAndLabel, True
>
> should work.
>
> HTH,
> Bernie
> MS Excel MVP
>
>
> "klysell" <(E-Mail Removed)> wrote in message
> news:8C41042A-F785-4FD8-8C7D-(E-Mail Removed)...
> > Hi,
> >
> > My macro parses codes on my summary sheet into separate pivot tables
> > contained on separate worksheets thereby using these individual codes as page
> > fields for these pivot tables. Because I have too much data, I had to create
> > a forumula driven variance column lying outside of the pivot table (else the
> > code that creates the pivot table crashes). However, now my print macros
> > don't work because for some reason, the print preview function reads all the
> > variance formulas (although blank) going to down to, say, row 2000. Instead
> > of nicely fitting the pivot table onto one, two or three pages, I have 65+
> > blank pages due to the formulas running down past my pivot table (these
> > variance formulas show a blank i.e. "" in cells below my pivot tables).
> >
> > Therefore, I either: 1) need to create a print area for just the pivot
> > table; or 2) delete all rows beneath the macro-generated pivot table
> > (starting row not known in advance).
> >
> > Any help would be appreciate.
> >
> > Cheers,
> >
> > Kent Lysell
> > IBM Consultant
> > Ottawa, Ontario

>
>
>

 
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
Too many rows or columns in pivot table koneil Microsoft Excel Misc 0 16th Dec 2007 10:48 AM
Non-nested rows/columns in a pivot table? =?Utf-8?B?SGVucmlr?= Microsoft Excel Misc 3 10th Oct 2006 12:32 PM
Too many rows or columns in my pivot-table =?Utf-8?B?bWFya3Vz?= Microsoft Excel Misc 1 14th Aug 2006 02:58 PM
pivot table - Can I pre-define rows and columns? =?Utf-8?B?V1JCYWlsZXk=?= Microsoft Excel Misc 3 17th May 2005 06:11 PM
Pivot Table Sum Columns and Rows =?Utf-8?B?cGV0ZXJo?= Microsoft Excel Misc 1 24th Aug 2004 09:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.