dcez
dcez

Reputation: 31

Macro to format y- axis in Excel

I've written some code to create a second y-axis in a chart. I recorded a macro when I formated the second y-axis and the code looks great. However, it doesn't work when I try to run it from the VBA code.. I've tried the Format Painter (the first y-axis), which would be optimal if it worked, and also by formating the second y-axis "by hand"

This is what I have (and it's doesn't work..) Formating the second y-axis to Calibri ("by hand"): ActiveChart.Axes(xlValue, xlSecondary).Select Selection.Format.TextFrame2.TextRange.Font.Name = "+mj-lt" 'This line doesn't work... Selection.Format.TextFrame2.TextRange.Font.Size = 14

Error code: Method TextFrame2 of Object 'ChartFormat' failed

Using Format Painter:

ActiveChart.Axes(xlValue).Select
Selection.Format.PickUp    'This line doesn't work...
ActiveChart.Axes(xlValue, xlSecondary).Select

Error code: Object doesn't support this property or method.

Does anyone know why none of the methods work or if there's a work around?

Upvotes: 1

Views: 1777

Answers (1)

dcez
dcez

Reputation: 31

I found a work around by using:

With ActiveChart.Axes(xlValue, xlSecondary).TickLabels.Font
   .Name = "Calibri"
   .Size = 16
End with

I haven't been able to solve the issue with Format Painter though...

Upvotes: 2

Related Questions