PDA

View Full Version : Conditional formatting



volabos
04-11-2017, 11:10 AM
Hi again,

The value in any cell in Excel can be of 2 types i.e. either a naked value (i.e. you give some value in the cell and then press enter) or a calculated value (i.e. cell value based on some formula and may have some dependency on values of other cell.)

I am looking for some formatting rule which will format the cell (e.g. change the size of font, make it underlined etc.) if the underlying value of the cell is a calculated value.

I also want such formatting rule to be applied throughout my excel Workbook.

Can someone here help me to create such a formatting rule.

Thanks for your time.

Logit
04-11-2017, 12:19 PM
.
.
Paste this code in the ThisWorkbook module :



Option Explicit


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.HasFormula Then
Target.Interior.Color = vbRed
Else
' remove background colour entirely (i.e. No Fill)
Target.Interior.ColorIndex = xlColorIndexNone
End If
End Sub




It checks all cells throughout the workbook for the EQUAL symbol. If the symbol is present, it colors the cell RED.

You can change the "Target.Interior.ColorIndex = xlColorIndexNone to the commands for formatting the cell.