Apr 19th 2013
By David Ringstrom, CPA
In a previous article, I described a technique that lets you tell at a glance if an individual cell is unlocked within a worksheet. In this article, I'll demonstrate how you can use conditional formatting to identify all unlocked cells within a worksheet range. This can serve both as an input aid, so that users know which cells they can affect, as well as an auditing tool, so that you know which cells are protected and which aren't.
We'll use the CELL function within Conditional Formatting to color unlocked cells. The CELL function provides information about worksheet cells, and takes this form:
The info_type argument signifies the type of information that we'd like to return about the cell. A couple of available info types include:
- protect – returns 0 if a cell is unlocked, or 1 if it is locked.
- filename – returns the workbook's file name.
- type – returns b if a cell is blank, l (lowercase L) if the cell contains text, or v if the cell contains anything else.
Details about other info types are available in a Microsoft support article. The reference argument is an optional argument that allows us to specify a range of one or more cells. To use the CELL function in conjunction with conditional formatting:
Set up the example shown in Figure 1. To save time, type Monday in cell A2 and then drag the fill handle down to create a series of days. After you enter 100 in cell B2 and 200 in cell B3, select those two cells and double-click the Fill Handle to complete the series. In cell B9, hold down the Alt key then press and release the equal sign (=) to create an instant sum.
Figure 1: Set up the example by using time-saving shortcuts.
We now want to select just the numeric input cells, as shown in Figure 2. To do so, press Ctrl-G (or F5) to display the Go To dialog box and then click the Special button. Choose Constants, clear the checkmarks for Text, Logicals, and Errors, and then click OK.
At this point, cells B2 through B8 should be selected. Press Ctrl-1 to display the Format Cells dialog box, clear the Locked checkbox on the Protection tab, and then click OK.
Figure 2: Use the Go To Special dialog box to select the numeric constants in the example. Then, use the Format Cells dialog box to unlock the selected cells.
We now want to select the used range of our spreadsheet, as illustrated in Figure 3. To do so, click on cell A1, and then hold down the Shift key while you tap the End and then Home keys.
Access the Conditional Formatting feature:
- Excel 2007 and later: Choose Conditional Formatting on the Home tab, New Rule, and then Use a Formula to Determine Which Cells to Format
- Excel 2003 and earlier: Choose Format, Conditional Formatting, and then change Cell Value Is to Formula Value is.
Enter the following formula:
Click the Format button, and choose a color from the Fill tab, and then click OK twice.
Figure 3: Use the CELL function to color the unlocked cells.
As illustrated in Figure 4, cells B2 through B8 should appear in the color that you chose. To test the feature, select cells B2 through B4, press Ctrl-1 to display the Format Cells dialog box, click Locked, and then click OK. The color should vanish from cells B2 through B4.
Figure 4: Check the Locked checkbox in the Format Cells dialog box to test your work.
You can easily remove Conditional Formatting at any time:
- Excel 2007 and later: Choose Conditional Formatting from the Home tab, click Clear Rules, and then Clear Rules from Entire Sheet. If you want to be more selective, select a range of cells before you access the Clear Rules command and then choose Clear Rules from Selected Cells.
- Excel 2003 and earlier: Select the range of cells with conditional formatting, choose Format, Conditional Formatting, and then click Delete. Select Condition 1 and then click OK twice.
Figure 5: Choose Clear Rules from Entire Sheet to remove the Conditional Formatting from your worksheet.
Read more articles by David Ringstrom.
About the author:
David H. Ringstrom, CPA heads up Accounting Advisors, Inc., an Atlanta-based software and database consulting firm providing training and consulting services nationwide. Contact David at [email protected] or follow him on Twitter. David speaks at conferences about Microsoft Excel, and presents webcasts for several CPE providers, including AccountingWEB partner CPE Link.