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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Worf

Well-known Member
Joined
Oct 30, 2011
Messages
4,183
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,675
Messages
5,838,712
Members
430,566
Latest member
ChanchalSingh

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