Creating Pivot Table with VBA

E

Eric Lecocq

Hello,

i have the following problem:

i try to create a pivot table with vba but it doesn't work.
i have some data (named columns A to N)

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"zac01!C1:C14").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable2"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"zac01!C1:C14").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable2"

i try to make the pivot

ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
With ActiveSheet.PivotTables("PivotTable2")
.ColumnGrand = False
.RowGrand = False
.SmallGrid = False
End With

when i add my fields, i receive an error: method addfields failed

ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array( _
"Sold-to Name", "Data"), ColumnFields:="Date",
PageFields:="Material"

=> at this moment, i can see a list of the fields (with the wizard, but
there is only one field in the list) ???????
how can this be ? I selected col A to N ?


than you for your help
 
T

Tom Ogilvy

In your code you specify:
SourceData:= _
"zac01!C1:C14").

try changing it to

SourceData:= _
"zac01!A1:N14").
 
E

Eric Lecocq

Thank you very much !!!!


Tom Ogilvy said:
In your code you specify:
SourceData:= _
"zac01!C1:C14").

try changing it to

SourceData:= _
"zac01!A1:N14").

--
Regards,
Tom Ogilvy


TableName:= TableName:=
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top