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 does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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