bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Formatting > Conditional Formatting > Highlighting Values in a Cell

Highlighting Values in a Cell

Summary: Excel allows you, through normal editing, to overwrite formulas in a cell with explicit values. Wouldn’t it be nice to know where such overwriting occurred, however? You can find out by applying some of the techniques discussed in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

Trev has a table of sales forecasts by product that several users review and update. The forecasts are initially set with various formulas, but the users are allowed to override the formulas by entering a value into any cell that contains one of the formulas. If a user does this, it would be helpful for Trev to have Excel somehow highlight that cell.

There are a couple of approaches you can take. First, you could use conditional formatting to do the highlighting. Set the conditional formatting to "Cell Value Is" "Not Equal To" and then enter the formula as the comparison. This will tell you when the value in the cell does not equal whatever the formula is, but a potential "gottcha" is if the person overrides the formula with the result of that formula. For instance, if the formula would have produced a result of "27" and the user types "27" into the cell.

Another possibility is to define a formula in an named constant, and then use that named constant in a conditional format. Follow these steps:

  1. Choose Name from the Insert menu, then choose Define. Excel displays the Define Name dialog box. If you are using Excel 2007, display the Formulas tab of the ribbon and, within the Defined Names group, click Define Name. Excel displays the New Name dialog box. (Click here to see a related figure.)
  2. In the Names in Workbook box (the Name box in Excel 2007), enter the name you want assigned to this formula. For this example, use CellHasNoFormula.
  3. Select whatever is in the Refers To box, at the bottom of the dialog box, and press Del. This gets rid of whatever Excel had there before.
  4. Enter the following formula in the Refers To box:
  5.      =NOT(GET.CELL(48,INDIRECT("rc",FALSE)))
    
  6. Click OK.

Now you can set up some conditional formats and use this named formula in the format. Simply set the condition to "Formula Is" and enter the following formula in the condition:

=CellHasNoFormula

The formula returns True or False, depending on whether there is a formula in the cell or nor. If there is no formula, then True is returned and whatever format you specify is applied to the cell.

Another approach is to use a user-defined function to return True or False, and then set up the conditional format. You could use a very simple macro, such as the following:

Function IsFormula(Check_Cell As Range) As Boolean
    Application.Volatile
    IsFormula = Check_Cell.HasFormula
End Function

You can then specify "Formula Is" in the conditional format, and use the following formula if, for instance, you are conditionally formatting cell C1:

=NOT(IsFormula(C1))

The formula returns True if there is no formula in the cell, so the conditional format is applied.

The only downside of using any of these formulas to determine if a formula is in the cell is that it cannot determine if the formula in the cell has been replaced with a different formula. This applies to both the macro approach and the defined formula approach.

A totally different approach is to rethink your worksheet a bit. You can separate cells for user input from those that use the formulas. The formula could use an IF function to see if the user entered something in the user input cell. If not, your formula would be used to determine a value; if so, then the user's input is used in preference to your formula. This approach allows you to keep the formulas you need, without them being overwritten by the user. This results in great integrity of the formulas and the worksheet results.

Tip #3224 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007


More Power! Expand your skills and make Excel really sing! It's all possible with macros. The best resource anywhere for macros is ExcelTips: The Macros. Check it out today!

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home
Vital News Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)