October 28, 2021
Good Morning All,
I have a piece of vba code that updates a chart layout if a pivot table is updated. (see below)
I have x 2 slicers and a graph on x1 worksheet (Prod Dashboard) & Pivot Table on another worksheet (Prod Hub) linked to slicers.
Slicers are called Section (Slicer_Section2) & Facility (Slicer_Facility1)
My error occurs when the user is filtering a facility and then selects a section on the slicer that doesn't contain that facility and subsequently runs the macro to change the chart layout which display the error 'parameter not found'.
Fix? Is it possible to have coding to only run the macro if the pivot table is populated with some data?
--------------------------------
My code Located on Prod Hub worksheet with pivot table.
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If Target.Name = "PivotTable1" Then
Sheets("Prod Dashboard").Activate
Application.Run "'hub.xlsm'!Test2"
End If
End Sub
--------------------------------------
My Macro
' Test2 Macro - Strikethrough line is highlighted yellow when debug selected. I believe this is due to it attempting to change chart layout with no data.
'
ActiveSheet.ChartObjects("Chart 10").Activate
ActiveSheet.ChartObjects("Chart 10").Activate
ActiveChart.ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(3).ChartType = xlLine
ActiveChart.FullSeriesCollection(3).AxisGroup = 1
ActiveChart.FullSeriesCollection(1).ChartType = xlLine
ActiveChart.FullSeriesCollection(2).ChartType = xlLine
ActiveChart.FullSeriesCollection(3).ChartType = xlColumnClustered
Range("G18").Select
End Sub
Any help greatly appreciated.
Andy
Trusted Members
Moderators
November 1, 2018
For a situation like this, it's probably simplest to just suppress the errors using something like:
On Error Resume Next
With ActiveSheet.ChartObjects("Chart 10").Chart
.ChartType = xlColumnClustered
.FullSeriesCollection(1).ChartType = xlColumnClustered
.FullSeriesCollection(1).AxisGroup = 1
.FullSeriesCollection(2).ChartType = xlColumnClustered
.FullSeriesCollection(2).AxisGroup = 1
.FullSeriesCollection(3).ChartType = xlLine
.FullSeriesCollection(3).AxisGroup = 1
.FullSeriesCollection(1).ChartType = xlLine
.FullSeriesCollection(2).ChartType = xlLine
.FullSeriesCollection(3).ChartType = xlColumnClustered
End With
End Sub
although I can't really see why you set the type twice for each series?
1 Guest(s)