Format Chart Text

As with all elements of a chart, you can customize the text that displays on the chart by changing the font attributes. When Excel adds text to a chart either as the chart title, axis labels, or even data labels, it applies default formatting to the specified text. For example, typically the text for a chart title is formatted using the default font, normally Arial, and bold with a font size of 12 point. You can customize the text of the ChartTitle object, and all other objects on the chart using the Font object.

The Font object enables you to set the font attributes for all text values. You use the properties associated with the Font object to set the font attributes you want to modify. By setting the font attributes, you ensure that the appearance of the text on the chart is uniform.

Excel enables you to format the text that displays on the chart. When you use the Font object properties with the ChartTitle object, you modify the look of the chart title. To change the text that Excel displays as the legend text, use the Font object properties with the Legend object. You can set the font attributes for the entire chart using the Font object with the ChartArea object. For example, if you want to change the font for the entire chart, you apply the Font object properties to the ChartArea object.

When you work with the ChartArea object, you can set the font settings for the entire chart and then use the individual objects to customize various portions of the chart. The following objects enable you to set the Font object:

ChartTitle, DataTable, Legend, Characters, AxisTitle, DataLabel, and TickLabels.

FORMAT CHART TEXT

FORMAT CHART TEXT

Excel Vba Chart Formatieren

-D Create a new subrouti

L"H Type Set SelectChart = ThisWorkbook.Charts(1), replacing ThisWorkbook. Charts(1) with the chart to format.

-Q Type With SelectChart.

-D Create a new subrouti ype Dim SelectChart As Chart, replacing SelectChart with the name of the chart variable.

L"H Type Set SelectChart = ThisWorkbook.Charts(1), replacing ThisWorkbook. Charts(1) with the chart to format.

-Q Type With SelectChart.

Note: See Chapter 4 for more information on using the With statement.

ype .ChartArea.Font.Name

= "Tahoma", replacing "Tahoma" with the name of the font to use for the chart.

Type .ChartArea.Font.Color = RGB(0, 0, 255), replacing (0, 0, 255) with the RGB color values.

WORKING WITH CHARTS

You may not always want to apply the same font settings to the entire chart object. For example, you may want to underline the first character in the chart title. To format specific characters with the text of an object, the AxisTitle, ChartTitle, and DataLabel objects enable you to use the Characters object. When you utilize this object, you specify the character within the text string where formatting should start as well as the number of characters to format. For example, to format the first character in the chart title that you want to underline, you type code similar to the sample coding. Notice that the Characters object includes two parameter values. The first parameter value, in example 1, indicates the character in the text string where Excel first applies the formatting. The second parameter value indicates the number of characters to which Excel applies formatting.

TYPE THIS:

ThisWorkbook.Charts(1).ChartTitle. Characters(1,2).Font.Underline = True

RESULT:

Excel underlines the first and second characters in the chart title, but all remaining characters maintain their original font settings. If you already set the BOLD property of the ChartTitle object, the first two characters are not bold and underlined.

Bold Charts

□ Type With .ChartTitle.Font.

Switch to Excel and run ■ Excel applies the specified the macro. text formatting to the chart.

□ Type With .ChartTitle.Font.

—O Type .Size = "14" replacing "14" with the font size for the chart title.

Specify additional Font property values.

Switch to Excel and run ■ Excel applies the specified the macro. text formatting to the chart.

0 -1

Responses

Post a comment