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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
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
 
Upvote 0
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
 
Upvote 0
You range spans from cell B1 to the last entry in column D. Where should the range span to?
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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
Back
Top