Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default VBA code for making a pivot table

I have written some code to make a pivot table from a sheet of data. When I
run it, however, it is eliminating some data in the table (not including it).
If I do the pivot table by hand, all the data is included. What is wrong
with my code?
What it is eliminating is some column fields: it includes 11, but leaves out
7. Can you tell me what I am doing wrong? Thanks!
Here is my code:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"data!C1:C27").CreatePivotTable TableDestination:="Pivot_table!R3C1",
TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10

ThisWorkbook.Sheets("Pivot_table").Select


ActiveSheet.Cells(3, 1).Select

ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("day", _
"Data"), ColumnFields:="country", PageFields:="year"


ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("day", _
"Data"), ColumnFields:="country", PageFields:="year"
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("new unique
senders")
.Orientation = xlDataField
.Caption = "Sum of new unique senders"
.Position = 1
.Function = xlSum
End With
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default VBA code for making a pivot table

Your SourceData only includes column C: "data!C1:C27"

It should probably include more columns. Instead of the range address,
you could use a dynamic range as the pivot source, and refer to the
range name in the code. There are instructions he

http://www.contextures.com/xlPivot01.html

KyWilde wrote:
I have written some code to make a pivot table from a sheet of data. When I
run it, however, it is eliminating some data in the table (not including it).
If I do the pivot table by hand, all the data is included. What is wrong
with my code?
What it is eliminating is some column fields: it includes 11, but leaves out
7. Can you tell me what I am doing wrong? Thanks!
Here is my code:

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"data!C1:C27").CreatePivotTable TableDestination:="Pivot_table!R3C1",
TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10

ThisWorkbook.Sheets("Pivot_table").Select


ActiveSheet.Cells(3, 1).Select

ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("day", _
"Data"), ColumnFields:="country", PageFields:="year"


ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("day", _
"Data"), ColumnFields:="country", PageFields:="year"
With ActiveSheet.PivotTables("PivotTable1").PivotFields ("new unique
senders")
.Orientation = xlDataField
.Caption = "Sum of new unique senders"
.Position = 1
.Function = xlSum
End With



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
Making Pivot Table row formatting stick Vicky Excel Discussion (Misc queries) 4 July 21st 07 05:32 PM
ADDING A TRENDLINE WHEN MAKING A CHART FROM A PIVOT TABLE leo Charts and Charting in Excel 1 May 2nd 07 03:57 PM
Making Text into Numbers, for Pivot Table Cubes traceye Excel Worksheet Functions 0 January 31st 07 11:04 AM
Making a pivot table report static. ideal Excel Discussion (Misc queries) 1 February 28th 06 05:35 PM
What is a field name in excel when making a pivot table? mr1176 Excel Discussion (Misc queries) 2 January 29th 06 06:34 AM


All times are GMT +1. The time now is 09:13 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"