Run time error '424'

wwrightchess

New Member
Joined
Apr 20, 2022
Messages
29
Office Version
  1. 365
Platform
  1. MacOS
I recorded the following macro but when I tried to run it again I get the error run time error '424' object required on the third line when it tries to set the axes title.

Sub Macro11()
'
' Macro11 Macro
'

'
Sheets("ff_plot").Select
ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Text = "Freezing Fraction"
Selection.Format.TextFrame2.TextRange.Characters.Text = "Freezing Fraction"
With Selection.Format.TextFrame2.TextRange.Characters(1, 17).ParagraphFormat
.TextDirection = msoTextDirectionLeftToRight
.Alignment = msoAlignCenter
End With
With Selection.Format.TextFrame2.TextRange.Characters(1, 17).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 10
.Italic = msoFalse
.Kerning = 12
.name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Strike = msoNoStrike
End With
ActiveChart.ChartArea.Select
End Sub
 
While I don't use the Mac version of Excel, I think this should work. The following code assumes that your chart is located on a chart sheet, and that the sheet is named "ff_plot". If the chart is actually embedded within a worksheet, replace this part of the code . . .

VBA Code:
With Sheets("ff_plot").Axes(Type:=xlValue)

with

VBA Code:
With Worksheets("ff_plot").ChartObjects("Chart 1").Chart.Axes(Type:=xlValue) 'change the chart name accordingly

Here's the code . . .

VBA Code:
    With Sheets("ff_plot").Axes(Type:=xlValue)
        .HasTitle = True
        With .AxisTitle
            .Text = "Freezing Fraction"
            With .Font
                .Name = "Arial"
                .Size = 10
            End With
            With .Format.TextFrame2.TextRange.ParagraphFormat
                .TextDirection = msoTextDirectionLeftToRight
                .Alignment = msoAlignCenter
            End With
        End With
    End With

Hope this helps!
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
In that case, the code I posted should work, although you may want to make changes, such as the font name. Have you tried it?
 
Upvote 0

Forum statistics

Threads
1,215,049
Messages
6,122,864
Members
449,097
Latest member
dbomb1414

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