Run-time error '91': at line code: ActiveChart.ClearToMatchStyle

codelearner

New Member
Joined
Jul 14, 2020
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
  3. Web
VBA Code:
Sub Run()
'
' Run Macro
' Run
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
    Columns("A:O").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "'OPS_Defect Report'!R1C1:R1048576C15", Version:=6).CreatePivotTable _
        TableDestination:="'OPS_Defect Report'!R2C17", TableName:="PivotTable7", _
        DefaultVersion:=6
    Sheets("OPS_Defect Report").Select
    Cells(2, 17).Select
    ActiveWindow.SmallScroll ToRight:=11
    With ActiveSheet.PivotTables("PivotTable7").PivotFields("Station")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable7").PivotFields("Defect")
        .Orientation = xlColumnField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable7").AddDataField ActiveSheet.PivotTables( _
        "PivotTable7").PivotFields("Defect Qty"), "Count of Defect Qty", xlCount
    With ActiveSheet.PivotTables("PivotTable7").PivotFields("Count of Defect Qty")
        .Caption = "Sum of Defect Qty"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable7").PivotFields("Station")
        .PivotItems("(blank)").Visible = False
    End With
    ActiveSheet.PivotTables("PivotTable7").PivotFields("Station").AutoSort _
        xlDescending, "Sum of Defect Qty"
    With ActiveSheet.PivotTables("PivotTable7").PivotFields("Defect")
        .PivotItems("(blank)").Visible = False
    End With
    ActiveWindow.SmallScroll ToRight:=5
    Range("R3:AD3").Select
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 90
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Columns("R:AD").Select
    Columns("R:AD").EntireColumn.AutoFit
    ActiveWindow.LargeScroll ToRight:=-1
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 7
    ActiveWindow.ScrollColumn = 8
    Selection.ColumnWidth = 8.27
    Range("S5").Select
    ActiveSheet.PivotTables("PivotTable7").PivotSelect "Station[All]", xlLabelOnly _
        + xlFirstRow, True
    ActiveChart.ClearToMatchStyle
    ActiveSheet.Shapes.AddChart2(297, xlColumnStacked).Select
    ActiveChart.SetSourceData Source:=Range("'OPS_Defect Report'!$Q$2:$AD$13")
    ActiveWindow.SmallScroll ToRight:=4
    ActiveSheet.Shapes("Chart 6").IncrementLeft 270
    ActiveSheet.Shapes("Chart 6").IncrementTop 180.5882677165
    Range("AA18").Select
End Sub
 

Attachments

  • VBA error 91.PNG
    VBA error 91.PNG
    19.6 KB · Views: 16
Last edited by a moderator:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Welcome to the forum
When posting code remember to click on <VBA/> icon and paste your code between the tags which makes it easier to read - thanks :)

Enter this line
VBA Code:
MsgBox TypeName(Selection)
above
VBA Code:
ActiveChart.ClearToMatchStyle

ActiveChart.......ClearToMatchStyle fails if a chart is not the selected object
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,680
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top