Create a pivot table in VBA

B

Bruno

Hi,
I created a macro (recorded macro)to make a pivot Table.
The generated code was the following:
(...)
Columns("A:H").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:= _
"relat!C1:C8").CreatePivotTable
TableDestination:="", TableName:= _
"TD Vendas"
ActiveSheet.Name = "TPVsIva"
ActiveSheet.PivotTableWizard
TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select

ActiveSheet.PivotTables("TD Vendas").SmallGrid = False

ActiveSheet.PivotTables("TD Vendas").AddFields
RowFields:=Array( _
"Estrutura", "Dados"), PageFields:="Loja"
(...)

When I run the macro, the last line genarates an error
(Addfields Rowfields line).
The error is : "Run Time Error '1004'" with the
message "It was not possible to execute the
Addfields method of the
PivotTables collection"

Which is the problem?
When I recorded the macro everything was OK.

Thanks in advance for your replys,
Bruno
...
 
B

Bruno

Hi people,

Can annyone help-me with this VBA error?

I forgot to said that I'm working with Excel 2000 with NT 4.

Thaks in advance
Bruno Cost
 

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