rmcginnis77
New Member
- Joined
- Apr 4, 2011
- Messages
- 1
I'm trying to create a Pivot Table via VBA. The tool I'm using gives me a skeleton and I created the pivot code via the macro recorder.
What I can't figur out is what other objects I need to define (and how)
The first code is the skeleton, the second part is the excel macro.
Sub QC_PostProcessing()
Dim MainWorksheet As Worksheet
Make sure your worksheet name matches!
Set MainWorksheet = ActiveWorkbook.Worksheets("Query1")
Dim DataRange As Range
Set DataRange = MainWorksheet.UsedRange
' Now that you have the data in DataRange you can process it.
Range("G1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Range").CreatePivotTable TableDestination:= _
"Query1", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
Charts.Add
ActiveChart.Location Where:=xlLocationAsNewSheet
.
.
.
Running the macro fails just after the range designation.
Thank you
What I can't figur out is what other objects I need to define (and how)
The first code is the skeleton, the second part is the excel macro.
Sub QC_PostProcessing()
Dim MainWorksheet As Worksheet
Make sure your worksheet name matches!
Set MainWorksheet = ActiveWorkbook.Worksheets("Query1")
Dim DataRange As Range
Set DataRange = MainWorksheet.UsedRange
' Now that you have the data in DataRange you can process it.
Range("G1").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Range").CreatePivotTable TableDestination:= _
"Query1", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion10
Charts.Add
ActiveChart.Location Where:=xlLocationAsNewSheet
.
.
.
Running the macro fails just after the range designation.
Thank you