Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Adding a Little Animation to Your Life
Converting a Range of URLs to Hyperlinks
Making the Formula Bar Persistent
Cells in a worksheet can contain values or they can contain formulas. At some time, you may wish to somehow highlight all the cells in your worksheet that contain formulas by coloring those cells. There are several ways you can approach and solve this problem. If you don't have a need to do the highlighting that often, a manual approach may be best. Follow these steps:
At this point, every cell in the worksheet that contains formulas is selected, and you can add color to those cells or format them as desired. This approach can be automated, if desired, by using a macro like the following:
Sub ColorFormulas()
ActiveSheet.Cells.SpecialCells(xlCellTypeFormulas, 23).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
End Sub
You can run this macro as often as necessary in order to highlight the various cells that contain formulas. The only problem is that if a formula is deleted from a cell that was previously highlighted, the highlighting remains; it is not removed automatically. In this case, a different macro approach is mandated. This macro acts on a range of cells you select before running the macro.
Sub ColorFunction()
For Each cell In Selection
If cell.HasFormula Then
With cell.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Else
cell.Interior.ColorIndex = xlNone
End If
Next cell
End Sub
The macro checks each cell in the range. If the cell contains a formula, then it is highlighted. If the cell does not contain a formula, then the highlight is turned off.
Another potential solution is to use a user-defined function along with the conditional formatting capabilities of Excel. Create the following function in the VBA Editor:
Function CellHasFormula(c As Range) As Boolean
CellHasFormula = c.HasFormula
End Function
With this function in place, you can use the conditional formatting capabilities of Excel (detailed elsewhere in ExcelTips) to check what the formula returns. In other words, you would set a conditional format that checked the result of this formula:
=CellHasFormula(A1)
If the result is true (the cell contains a formula), then your conditional format is applied.
It is interesting to note that you don't have to create a VBA macro to use the conditional formatting route, if you don't want to. (Some people have a natural aversion to using macros.) Instead, you can follow these steps if you are using a version of Excel prior to Excel 2007:
=GET.CELL(48,INDIRECT("rc",FALSE))
If you are using Excel 2007, follow these steps instead:
=GET.CELL(48,INDIRECT("rc",FALSE))
Now you can follow the techniques previously outlined for setting up the conditional formatting. The only difference is that the conditional format should check for the following formula, instead:
=FormulaInCell
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2766) applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Got the Time? Understanding the ins and outs of working with times and dates can be confusing. Remove the confusion--ExcelTips: Times and Dates is an invaluable resource for learning how best to work with times and dates.