Hey Guys!
Im trying to do a Macro to post a chart from a pivot table ( i used record macro first to understand what was being done). One problem through i cannot get the row variable in the pivot table to be correct, (highlighted in black) I think it has something to do with the dynamic range.... thanks for the help guys
Sub Macro5()
'
' Macro5 Macro
'
'
Range("A2:AD2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlUp)).Select
Range("A2:AD2206").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"TotalGama c Sku!R2C1:R2206C30", Version:=xlPivotTableVersion14). _
CreatePivotTable TableDestination:="", TableName:="PivotTable4" _
, DefaultVersion:=xlPivotTableVersion14
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=Range("Sheet6!$A$1:$C$18")
ActiveSheet.Shapes("Chart 1").IncrementLeft 192
ActiveSheet.Shapes("Chart 1").IncrementTop 15
With ActiveSheet.PivotTables("PivotTable4").PivotFields("DC")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable4").PivotFields( _
"Categorização Margem Son")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable4").AddDataField ActiveSheet.PivotTables( _
"PivotTable4").PivotFields("Categorização Margem Son"), _
"Count of Categorização Margem Son", xlCount
End Sub
Bookmarks