Automating Excel Chart Titles
Recently, I described how you can use Excel's Table feature to have charts expand automatically. In this article, I'll show how you can further automate your chart with a self-updating title.
To create a chart in Excel 2007 and later, create a data set like the one shown in cells A1 through E3. Next click on cell A1, choose Insert, Column, and then the first 2-D option.
The next step is to add a title to the chart. To do so, click once on the chart to select it, and then choose Layout, Chart Title, and then Above Chart. To manually change the title, you can click on the title field within the chart and edit the text as desired. However, we can use a formula to make the title dynamic instead.
To automate your chart title, use two worksheet functions together:
- COUNTA - This worksheet function returns the number of non-blank cells in a given range.
- INDEX - This worksheet function returns data from cell coordinates that you provide.
Use COUNTA to determine the number of non-blank cells in row 1. This assumes you won't have any data to the right of your source data. If you've entered four months of data, then COUNTA will return the number 5, because there will be five non-blank cells in the row. You'll then use the INDEX function to return the word "April." To do so, you'll tell the INDEX function to look across row 1 of your worksheet, and return data from the nth cell, as provided by COUNTA. The formula will take this form:
You may wish to add additional narrative, such as the word "Sales." To do so, you can use a technique known as concatenation. Although Excel has a CONCATENATE worksheet function, I use this approach instead:
In essence, I use an ampersand to join the additional text to my formula. Such text must be enclosed in double quotes.
The aforementioned formula can be entered in any cell in your worksheet. I've chosen to place it in cell A5, just below my source data.
You're now ready to automate your chart title. To do so, click on the title of your chart, and then click in the Formula bar. Click on the cell that contains your title formula, such as cell A5 in this case, and then press Enter.
To make the chart completely dynamic, click on cell A1, choose Insert, Table, and then press Enter. My previous article in this series describes this technique in more detail.
Your chart is now dynamic. If you've followed all of the steps in this article, you should be able to add a new column of data for May and see the new data and title automatically.
Note: There are a couple of caveats to be aware of with regard to automating charts. First, if you make the data into a Table before you create your chart, Excel may group the data. To change this, click the Switch Rows/Columns button on the Design tab. Secondly, when automating chart titles, you must reference a worksheet cell, and your formula reference must include a worksheet name. Thus, you can't click on the title and enter =A5 in the formula bar. You must instead use the form =Sheet1!A5.
Stay tuned, as my next article in this series will explain the technique I use to utilize clip art within charts.
David H. Ringstrom, CPA, is an author and nationally recognized instructor who teaches scores of webinars each year. His Excel courses are based on over 25 years of consulting and teaching experience. His mantra is “Either you work Excel, or it works you.” David offers spreadsheet and database consulting services nationwide.