code for pivot tables

fahimip

New Member
Joined
Sep 27, 2006
Messages
35
Hi guys

I would like to write some code to create a pivot table.

the problem is the code that i have seems to cut off some of the data, as i need to use this code on a regular basis this is no good to me.

heres what ive got so far;

Range(Range("b1"), Range("d65536").End(xlUp)).Select

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"HD!R1C2:R11C4").CreatePivotTable TableDestination:= _
"'[S Template.xls]HD'!R2C7", TableName:="PivotTable3", DefaultVersion:= _
xlPivotTableVersion10
With ActiveSheet.PivotTables("PivotTable3").PivotFields("COMPANY")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("CODE")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("QTY"), "Sum of QTY", xlSum


Any ideas?

Thanks
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

mrhartley

Well-known Member
Joined
Mar 8, 2005
Messages
564
Hi, I dont think I can help all that much but when you say data being cut off, are columns being cut off or rows.

~Mark
 

fahimip

New Member
Joined
Sep 27, 2006
Messages
35
Hi

It seems to be cutting off rows,

the columns are always in the same place when i repeat the code, but the rows change in number each time the code is used.

Cheers
 

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,808
Office Version
  1. 365
Platform
  1. Windows
You range spans from cell B1 to the last entry in column D. Where should the range span to?
 

Watch MrExcel Video

Forum statistics

Threads
1,133,463
Messages
5,658,912
Members
418,476
Latest member
Tristram_ZX81

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top