When creating charts in Excel, it’s sometimes useful to force line breaks for the purpose of composing better visualizations. Take the chart shown in Image 3-9, for example. Here, the X-axis labels in the chart include the data value in addition to the sales rep. This setup works well when you don’t want to inundate your chart with data labels.
The secret to this trick is to use the CHAR() function in a formula that makes up your chart labels (see Image 3-10).
Even nonprinting characters have codes. The code for a space is 32. The code for a line break is 10.
You can call up any character in a formula by using the CHAR() function. The example shown in Figure 3-10 calls up the line break character and joins it with the values in cells A3 and C3:
=A3 & CHAR(10) & C3
The cell itself doesn’t show the line break unless you have wrap text applied. But even if you don’t, any chart using this kind of formula will display the data returned by the formula with the line breaks.
Image 3-9: The X-axis labels in this chart include a line break and a reference to the data values. |
Image 3-10: Using the CHAR() function to force a line break between sales rep name and data value. |
How it works
Every character in Excel has an associated ANSI character code. The ANSI character code is a Windows system code set that defines the characters you see on your screen. The ANSI character set consists of 255 characters, numbered from 1 to 255. The uppercase letter A is character number 97. The number 9 is character 57.Even nonprinting characters have codes. The code for a space is 32. The code for a line break is 10.
You can call up any character in a formula by using the CHAR() function. The example shown in Figure 3-10 calls up the line break character and joins it with the values in cells A3 and C3:
=A3 & CHAR(10) & C3
The cell itself doesn’t show the line break unless you have wrap text applied. But even if you don’t, any chart using this kind of formula will display the data returned by the formula with the line breaks.