I am trying to write a macro to create a pivot chart. I need the pivot chart to be a bar chart that has the columns filtered to only show 3 of the columns. Here is the code I have so far.
'Define Data Range
LastRow = Dsheet.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = Dsheet.Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = Dsheet.Cells(1, 1).Resize(LastRow, LastCol)
'Define Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PRange)
'Insert Blank Pivot Table
Set PTable = PCache.CreatePivotTable _
(TableDestination:=PSheet.Cells(1, 1), TableName:="Studies Impacted")
'Insert Column Fields
With ActiveSheet.PivotTables("Studies Impacted").PivotFields("Study")
.Orientation = xlColumnField
.Position = 1
End With
'Insert Row Fields
With ActiveSheet.PivotTables("Studies Impacted").PivotFields("Workstream")
.Orientation = xlRowField
.Position = 1
End With
'Insert Data Field
With ActiveSheet.PivotTables("Studies Impacted").PivotFields("Study")
.Orientation = xlDataField
.Position = 1
.Function = xlCount
.NumberFormat = "#,##0"
.Name = "Status Count"
End With
'Format Pivot
ActiveSheet.PivotTables("Studies Impacted").ShowTableStyleRowStripes = True
ActiveSheet.PivotTables("Studies Impacted").TableStyle2 = "PivotStyleMedium9"
I have tried using >add FilterType but it doesn't seem to work. I have also tried defining it as a PivotField but again, no results.
The result I want is a bar chart with only 3 of the studies being shown for each workstream. Instead, I am getting all of the studies.