Changing font color depending on cell contents


Posted by Martin on March 22, 2001 5:22 AM

Hello everyone

I want to be able to distinguish between cells which contain a formula (or a simple calculation) and cells where the value has been typed directly.

E.g. if cell a1 contains a formula like =b2+c2 I want the color to black, but if I type a number directly into cell a1 I want the font color to change to blue.

I've tried to use conditional formatting, and I can get it to distinguish between text and values, but not between formulas and typed values.

Any suggestions ?

Thanks

Posted by Celia on March 22, 2001 5:45 AM


Martin
Here's a slightly different approach that I use.
I have the following 2 macros in my Personal workbook and attached to two buttons. The first macro removes all cell interior colors and then makes the interior color of all cells with formulas blue. The second macro removes all cell interior colors.
(Note : the cell highlighting is not automatic - the macros have to be run to update the highlighting.)

Sub IdentifyFormulae_Add()
On Error GoTo e:
With Cells
.Interior.ColorIndex = 0
.SpecialCells(xlFormulas).Interior.ColorIndex = 20
End With
Exit Sub
e: MsgBox "There are no cells with formulas"
End Sub

Sub IdentifyFormulae_Remove()
Cells.Interior.ColorIndex = 0
End Sub

Posted by Bob on March 22, 2001 8:13 AM

Try this, you might want to change "I" to whatever cell you
want to search in....

Private Sub CommandButton1_Click()
Dim LastRow As Variant
Dim x As Variant

LastRow = Range("A65536").End(xlUp).Row

For x = 2 To LastRow
If Range("I" & x).Formula = True Then
Range("I" & x).Select
With Selection.Interior
.ColorIndex = 0
End With

Else

Range("I" & x).Select
With Selection.Interior
.ColorIndex = 1
End With

End If
'MsgBox "TEST"
Next x
End Sub

Posted by mseyf on March 22, 2001 8:42 AM

here's a non-VBA solution-

select cell A1
from menu bar select Insert>Name>Define
for 'Names in workbook' enter CellType
in 'Refers to' enter =get.cell(48,a1)
click ok

highlight the range to 'Conditional Format'
in the Conditional Format dialog box, 'Formula is' to highlight formulas is =CellType, and to highlight entered values is =not(CellType)

(Get.Cell is a holdover from the macro language before VBA)

HTH

Mark



Posted by mseyf on March 22, 2001 8:53 AM

Oops:

to keep blank cell from being highlighted, change the 'is formula' for entered values to
=and(not(CellType),not(isblank(xx)))
substituting the active cell address for the the range you are trying to conditionally format (i.e. A1)
sorry I didn't think it through better the first time.

Mark