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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,853
Members
449,194
Latest member
HellScout

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