Can't seem to create a Pivot Table with VBA ?

T

Tim

I keep getting errors when trying to create a pivot table from
existing sheet data... I'm actually using a web query to populate the
"RawData" sheet, then trying to use that data to create a pivot
table...

Does anyone have any ideas why this might not be working?

Thank in advance,
Tim


Dim PTCache As PivotCache
Dim Table As PivotTable

Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=Range("RawData!A1:F245"))
Set Table = PTCache.CreatePivotTable(TableDestination:=Sheets("Upgrade
Report").Range("a18"), TableName:="ptUpgrade")

With Table
With .CubeFields(sRowField1)
.Orientation = xlRowField
.Position = 1
End With

If sRowField2 <> "none" Then
With .CubeFields(sRowField2)
.Orientation = xlRowField
.Position = 2
End With
End If

With .CubeFields(sDataField)
.Orientation = xlDataField
.Position = 1
End With

End With
 
T

Tom Ogilvy

well, if you are getting data from a worksheet, I doubt you would have
Cubefields.

Why not turn on the macro recorder and create the table manually using your
data. Then turn it off and enrich the recorded code to do what you want.
 

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

Similar Threads

Pivot table in VB 3
[Microsoft][ODBC Driver Manager] error 3
VBA Pivot Table Error 1
Pivot table 1
Pivot table sum data 1
Format Pivot total rows 2
Pivot table code question 2
Playing back a Pivot Table macros 2

Top