Run-time error '424' Object Required. VBA Horizontal Axis on Pivot Chart

mcrisp72

New Member
Joined
Mar 11, 2016
Messages
1
I am beginner user of VBA, and I am trying to make a macro for work. I need to create one that takes a large amount of data in order to create 4 pivot charts and tables. Right now, I am having a problem with the code for creating a horizontal axis. I recorded the macro, but I keep getting this run-time error '424' Object required. The code in red is where I'm having a problem. Any help would be great. Thanks

End With
ActiveChart.ChartArea.Select
ActiveSheet.Shapes("Chart 1").Height = 480.24
ActiveSheet.Shapes("Chart 1").Width = 488.88
Application.CommandBars("Format Object").Visible = False
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
ActiveWindow.SmallScroll Down:=9
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Number of Breaks"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Number of Breaks"
With Selection.Format.TextFrame2.TextRange.Characters(1, 16).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
 

Some videos you may like

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,100
Welcome to the Board

Code:
Sub Crisp()
Dim vax As Axis, hax As Axis, ht$, tf As TextFrame2
ActiveSheet.Shapes("Chart 1").Height = 480
ActiveSheet.Shapes("Chart 1").Width = 488.88
Application.CommandBars("Format Object").Visible = False
ActiveChart.SetElement (306)
ActiveWorkbook.ShowPivotTableFieldList = False
Set vax = ActiveChart.Axes(xlValue, xlPrimary)              ' Y axis
vax.HasTitle = True                                         ' make sure title exists
ht = "Horizontal"
vax.AxisTitle.Text = "Vertical"
Set hax = ActiveChart.Axes(xlCategory, xlPrimary)           ' X axis
hax.HasTitle = True
hax.AxisTitle.Text = ht
Set tf = hax.AxisTitle.Format.TextFrame2
With tf.TextRange.Characters(1, Len(ht)).ParagraphFormat
    .TextDirection = msoTextDirectionLeftToRight
    .Alignment = msoAlignCenter
End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,123,493
Messages
5,601,998
Members
414,490
Latest member
Rip181

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
Top