Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50085

How to change the Font Properties of Chart Primary/Secondary X-Y Axis Title using VBA ?

$
0
0
How to change the Font Properties of Chart Primary/Secondary X-Y Axis Title using VBA ?

Dear Forum,

I am trying to create a Basic Clustered Column Chart using VBA and have made a rough Chart which can be modified later , however I need the Vertical Y-Axis Title to be formatted differently with certain specifications such as want to change the following details:

Font Size = 15
Font Style = Bold
Font.Name = "Times New Roman"
Font.ColorIndex = "Yellow"

But I am not able to do so and also need help to keep the Chart Y-Axis Title connected to a Cell - F2 and also instead of hard-coding the SheetName if the Active Sheet Name also could be used...

Please find my code below:



Code:

Sub Create_Basic_Chart()
'This Macro Creates a Basic-Clustered Column chart in excel.

ActiveSheet.Shapes.AddChart.Select
ActiveChart.SetSourceData Source:=Range("'Basic Pivot-3'!$A$1:$E$6")
ActiveChart.ChartType = xlColumnClustered


'Position of the Chart Code
ActiveSheet.ChartObjects(1).Left = ActiveSheet.Columns(1).Left + 10
ActiveSheet.ChartObjects(1).Top = ActiveSheet.Rows(20).Top - 150

    ActiveChart.ChartStyle = 42
    ActiveChart.ClearToMatchStyle
    ActiveChart.SetElement (msoElementChartTitleAboveChart)
    ActiveWorkbook.ShowPivotChartActiveFields = False
    ActiveChart.SetElement (msoElementPrimaryValueAxisTitleVertical)
   

With ActiveChart
    'chart name
    .HasTitle = True
    .ChartTitle.Characters.Text = "Chart Name"
    'X axis name
    '.Axes(xlCategory, xlPrimary).HasTitle = True
    '.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X-Axis"
   
    'With .Axes(xlCategory, xlPrimary).AxisTitle.Font
   
        '.Name = "Times New Roman"
        '.FontStyle = "Bold"
        '.Size = 15
        '.ColorIndex = 4
   
    'End With
   
    'y-axis name
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y-Axis"
   
   
    'With .Axes(xlCategory, xlSecondary).AxisTitle.Font
   
        '.Name = "Times New Roman"
        '.FontStyle = "Bold"
        '.Size = 15
        '.ColorIndex = 4
   
    'End With
   
   
   
End With

With ActiveChart.Axes(xlValue, xlPrimary)
        .AxisTitle.Orientation = 90          'xlDownward
End With


End Sub

Warm Regards
e4excel

Viewing all articles
Browse latest Browse all 50085

Trending Articles