Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Making Pivot Table row formatting stick | Excel Discussion (Misc queries) | |||
ADDING A TRENDLINE WHEN MAKING A CHART FROM A PIVOT TABLE | Charts and Charting in Excel | |||
Making Text into Numbers, for Pivot Table Cubes | Excel Worksheet Functions | |||
Making a pivot table report static. | Excel Discussion (Misc queries) | |||
What is a field name in excel when making a pivot table? | Excel Discussion (Misc queries) |