Listing Formatting a Basic Chart

Sub FormattingCharts() Dim cht As Chart Dim ws As Worksheet Dim ax As Axis

Set ws = ThisWorkbook.Worksheets("Basic Chart") Set cht = GetChartByCaption(ws, "GDP")

If Not cht Is Nothing Then

' format category axis

Set ax = cht.Axes(xlCategory)

With ax

.AxisTitle.Font.Size = 12 .AxisTitle.Font.Color = vbRed End With

' format value axis

Set ax = cht.Axes(xlValue)

With ax

.HasMinorGridlines = True

.MinorGridlines.Border.LineStyle = xlDashDot End With

' format plot area With cht.PlotArea

.Border.LineStyle = xlDash .Border.Color = vbRed .Interior.Color = vbWhite .Width = cht.PlotArea.Width + 10 .Height = cht.PlotArea.Height + 10 End With

' format misc other cht.ChartArea.Interior.Color = vbWhite cht.Legend.Position = xlLegendPositionBottom End If

Set ax = Nothing Set cht = Nothing Set ws = Nothing End Sub

Although all of this should appear relatively straightforward, I hope that you don't have to do much chart manipulation via code for the reasons given earlier. Creating presentation-quality charts requires an iterative design approach that can only be done manually (at least the first time). The approach is to design a nice chart manually that you then use as a template when you need to, reserving any code manipulation for relatively minor changes such as changing titles, colors, or perhaps changing the source data range.

0 0

Post a comment