Conditional Formatting...

Home Search Site Map

Up
AutoFormat...
Cells...
Column
Conditional Formatting...
Row
Sheet
Style...

New! Excel User Group Now Open @ www.excelusergroup.org, Check It Out!


Menu command Type What happens next?
Conditional Formatting... ...

Although a little conditional formatting can be achieved through the standard formatting codes under 'Format>Cells...', in versions from 97 up, Excel has had the hugely improved ability to apply any worksheet format, colour, pattern, border, etc., based on cell value conditions or the result of a formula condition.

The dialog used is below. (Showing two of the maximum 3 conditions, one box set for a cell value and one for a formula).

All formats set are applied when the result of the condition is 'True' for example using 'Cell Value Is' setting, the following dialog will force the selected cell(s) to show bold and red when the value in them is between 0 and -100 (True). (You can, of course, replace the values with cell references, e.g. between A1 and A2).

The 'Formula Is' option can be utilised when you are looking for more control over the condition. Remember always however, that the format is applied when the condition is true. Below we can change the colour of the font in the cell in which the formatting is set to red and make it bold, when the value in cell A1 is greater than 100.

As mentioned earlier, you can set up to a maximum of three conditions on a cell or range of cells and if, at a later date, you wish to remove some, you can press the 'delete...' button and select which of the three you wish to remove, as in the dialog shown.

VBA Sub ApplyCondFormat()
'Dimension Variables
Dim fMat As FormatCondition
Dim myRange As Range
Set myRange = Range("A1")
'Check for existence of existing formats and delete
If myRange.FormatConditions.Count > 0 Then
For Each fMat In myRange.FormatConditions
fMat.Delete
Next fMat
End If
'Create new format
Set fMat = myRange.FormatConditions.Add(xlCellValue, xlLess, "100")
'Set font to bold/red when condition is true
With fMat
With .Font
.ColorIndex = 3
.Bold = True
End With
End With
End Sub

Top

Copyright Nick Hodge 2008. All Rights Reserved.