Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can't seem to create a Pivot Table with VBA ?

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:=xlDatab ase,
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Can't seem to create a Pivot Table with VBA ?

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.

--
Regards,
Tom Ogilvy

"Tim" wrote in message
om...
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:=xlDatab ase,
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create pivot table from existing pivot table in excel 2007 Udayraj Dhulekar Excel Discussion (Misc queries) 2 July 8th 13 08:22 PM
can I create pivot table from two other pivot tables? pjk@boro Excel Discussion (Misc queries) 5 June 13th 09 12:13 PM
How do I create multiple pivot charts from one pivot table? Rudy Charts and Charting in Excel 1 March 17th 06 10:01 PM
pivot table: create worksheetsheet using pivot table Pivot Tables and New Worksheets Excel Discussion (Misc queries) 1 June 1st 05 10:01 PM
How do I create a pivot table if the pivot table icon or menu ite. Lynn@WS Charts and Charting in Excel 1 December 16th 04 02:36 AM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"