In Recipe 1.3, I discussed how to format cells to specify the type of data (e.g., text, numbers, currency, etc.). In this recipe, I'll show you a few other formatting techniques. Take a look at the spreadsheet in Figure 1-16.
This simple spreadsheet merely calculates values for a function of the form y = x n, where n is the exponent shown on the spreadsheet. It also calculates the cumulative area under the curve from 0 to x. The results are plotted on a chart adjacent to the calculation table. Chapter 4 covers charting in detail, so I won't discuss the chart here. Instead I want to focus on the calculation table.
I could have simply filled in a column of x values, entered formulas for the y and area values, and left it at that. However, that would look messy. More than likely you'll want to include your calculations in reports or share them with others, so making your spreadsheets presentable is a good idea. Formatting also serves as a form of documentation so that you can come back to a spreadsheet weeks or years later and quickly see what you did. There's (almost) nothing worse than opening an old spreadsheet and seeing just a grid of scattered numbers.
There are many ways to format your spreadsheet. In this example, I added a text label, in italics, in the cell C2 to indicate the purpose of the value in cell D2. I also added some borders around the table of calculations and delineated the column headings with a filled background and bold text. I also centered the column labels above the data instead of using the default left justification for text. If you're a keen observer, you may have noticed that I also changed the column width of several columns—I reduced the width of columns A and B so they wouldn't take up too much space and I increased the width of column E to accommodate the area column label. These are some of the most common formatting tasks I make on virtually every spreadsheet I write. They are simple and effective.
You can access Excel's formatting functions via the Format menu . There you'll find options for formatting cells, whole rows or columns, and even the entire spreadsheet. I personally use the cell formatting options the most. You've already seen how to access the Format Cells dialog box in Recipe 1.3, and as shown in Figure 1-6. You can use the main menu bar or the shortcut key combination, Ctrl-1, to open the Format Cells dialog box.
The Number tab displays the data type formatting options discussed earlier. The other tabs give you control of other cell aspects:
Set the position, orientation, and justification of text within a cell. You can also specify whether long text should wrap around, creating multiple lines of text in a single cell.
Specify the font type, style, and size of text to appear in a cell. For example, you could specify Arial font type with a bold style and a size of 10 points.
Add borders to any edge of a cell. You can select from a variety of line styles, including solid, dashed, and dotted, among others, and even set the line thickness.
Set the background color or pattern for a cell.
Specify whether a cell is protected (meaning it can't be changed without a password) and whether a cell is hidden.
While the Format Cells dialog box presents you with many cell formatting options, I prefer to use the toolbars for quick formatting tasks. If you look closely at Figure 1-16, you'll see the formatting toolbar visible just above the formula bar. This toolbar contains buttons to change a cell's font, justification, data type, number of decimal places, indention, borders, fill patterns, text color, and more. You can customize this toolbar as discussed in Recipe 1.1.
There may be times when you want to clear all the formats applied to a cell. To do so, select the cell whose formats you want to clear and then select Edit → Clear → Formats from the main menu bar.
The formatting options discussed here are common and useful. There are other formatting options that may come in handy from time to time, although you probably will not use them too often. These options include the row, column, and spreadsheet formatting options mentioned earlier, as well as others such as conditional formatting, which allows you to set formatting for a cell contingent on the value of the cell relative to some criterion you specify. We'll make use of these other formatting options throughout the remainder of the book. For the time being, you can read more about formatting options in Excel's built-in help system. To do so, open Excel Help by pressing Ctrl-F1 and click the "Table of Contents" link. Look for the "Working with Data" topic and click on it to reveal a list of subtopics. Look for the "Formatting Data" subtopic and click it to see a list of specific formatting-related topics.