#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Pivot Table

Hi,
I am doing an assignment for school and have run into some
problems. Firstly we have to write a macro to filter data
from a spreadsheet. Then according to the data make a
pivot table. The code generated by recording a macro works
if the number of rows are the same but because of the
filter function this is not the case.
I am wondering if someone could help be change or access
the rows through programming. The code is currently:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"Temp!R1C1:R262C13").CreatePivotTable
TableDestination:=Range("A264"), _
TableName:="PivotTable2"
and it is the Sorcedata:="Temp!R1C1:R262:C13" that is
causing the headaches
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Pivot Table

Sophie: try one of these

[sheet!address] is a short way of coding a range
currentregion is like pressing ctrl* to expand a range
until range is bordered by empty cells.

if the Pivot already exitst in a264 you'll have to clear it first
otherwise the code will generate an error.


Sub mkPiv()
ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=[temp!a1].CurrentRegion).CreatePivotTable _
TableDestination:=[a264], TableName:="PivotTable2"
End Sub

Sub mkPiv2()
ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=Range([temp!a1], [temp!a65536].End(xlUp)).Resize(, _
2)).CreatePivotTable _
TableDestination:=[a264], TableName:="PivotTable2"
End Sub


keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


"Sophie" wrote:

Hi,
I am doing an assignment for school and have run into some
problems. Firstly we have to write a macro to filter data
from a spreadsheet. Then according to the data make a
pivot table. The code generated by recording a macro works
if the number of rows are the same but because of the
filter function this is not the case.
I am wondering if someone could help be change or access
the rows through programming. The code is currently:
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
"Temp!R1C1:R262C13").CreatePivotTable
TableDestination:=Range("A264"), _
TableName:="PivotTable2"
and it is the Sorcedata:="Temp!R1C1:R262:C13" that is
causing the headaches
Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Pivot Table

typo!
resize s/b 13

Sub mkPiv2()
ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=Range([temp!a1], [temp!a65536].End(xlUp)). _
Resize(,13)).CreatePivotTable _
TableDestination:=[a264], TableName:="PivotTable2"
End Sub

cheerz!

keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


keepitcool wrote:

Sub mkPiv2()
ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=Range([temp!a1], [temp!a65536].End(xlUp)).Resize(, _
13)).CreatePivotTable _
TableDestination:=[a264], TableName:="PivotTable2"
End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
Print Pivot Table headers on pages with Pivot Table tsgoose Excel Worksheet Functions 0 December 9th 08 08:14 PM
Copying values from pivot table to cells outside pivot table richzip Excel Discussion (Misc queries) 4 January 16th 08 11:03 PM
How do I create a pivot table if the pivot table icon or menu ite. Lynn@WS Charts and Charting in Excel 1 December 16th 04 02:36 AM
Help required with setting up a pivot table with the source on sheet1 to have the pivot table created on sheet called "report" Diana[_5_] Excel Programming 0 August 21st 03 10:19 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"