MacroAlan
New Member
- Joined
- Aug 30, 2004
- Messages
- 31
I have built my file in Access, ported to Excel and now opened Excel to add PivotTables. The pivot tables are working great.
I added charts but both are showing the same; as though they are working off the same pivot table. I need the 2nd to work off the 2nd named pivot table.
I call the code to build the second:
Then the macro creates the pivot table and attempts to create the Chart.
How do I will the chart to use the “PivShtNm” pivot for its data?
I added charts but both are showing the same; as though they are working off the same pivot table. I need the 2nd to work off the 2nd named pivot table.
I call the code to build the second:
Code:
PivotThe2nd Lrow, NewWS, RST!Pivot2Pos, RST!PivotSheet, RST!Piv2Nm
' Last row in datasheet, current worksheet name, Position for the Pivot (not working yet), Named pivot sheet, pivot table name
Code:
Sub PivotThe2nd(LastRow As LongPtr, SourceSht As String, PivPos As Integer, PivSht As String, PivShtNm As String)
Dim Qut As String
Dim PC As PivotCache
Dim shtSrc As Worksheet
Dim shtDest As Worksheet
Set shtSrc = Sheets(SourceSht) 'ActiveSheet
Set shtDest = Sheets(PivSht)
Set PC = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:=shtSrc.Range("A1").CurrentRegion)
PC.CreatePivotTable tabledestination:=Range("M3"), _
TableName:=PivShtNm
With shtDest.PivotTables(PivShtNm)
.InGridDropZones = True
.RowAxisLayout xlTabularRow
End With
With shtDest
.PivotTables(PivShtNm).AddDataField .PivotTables(PivShtNm).PivotFields("Order No"), "Count Order No", xlCount
.PivotTables(PivShtNm).PivotFields("Order Date Month").Orientation = xlColumnField
.PivotTables(PivShtNm).PivotFields("Lead Time Violation").Orientation = xlRowField
.PivotTables(PivShtNm).PivotFields("NATL").Orientation = xlPageField
.PivotTables(PivShtNm).PivotFields("NATL").CurrentPage = "Natl"
.PivotTables(PivShtNm).ColumnGrand = False
.PivotTables(PivShtNm).RowGrand = False
End With
shtDest.Shapes.AddChart2(297, xlColumnStacked).Select
ActiveChart.SetSourceData source:=PivotTables(PivShtNm) 'not working ESP?
Set shtDest = Nothing
Set PC = Nothing
End Sub