Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
change font colour if cell contains function - programmatically
How do I get the font color to be black if cells(3,3) contains "=today()"
but to be blue if cells(3,3) contains (for example) "30 Oct 2004"? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
change font colour if cell contains function - programmatically
Here's the code way:
Sub test() With Cells(3, 3) .Interior.Color = IIf(.HasFormula, vbBlue, vbBlack) End With End Sub There is also a Named Range method, which is kind of dodgy and crashes XL97 users under specific conditions - on my website "IsFormula" -- Rob van Gelder - http://www.vangelder.co.nz/excel "fitful_thought" wrote in message ... How do I get the font color to be black if cells(3,3) contains "=today()" but to be blue if cells(3,3) contains (for example) "30 Oct 2004"? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
change font colour if cell contains function - programmatically
Hi fitful_thought,
fitful_thought wrote: How do I get the font color to be black if cells(3,3) contains "=today()" but to be blue if cells(3,3) contains (for example) "30 Oct 2004"? Something like this may do what you need: Sub ColorCells() On Error Resume Next With Sheet1.UsedRange .SpecialCells(xlCellTypeFormulas).Font.Color = vbBlack .SpecialCells(xlCellTypeConstants).Font.Color = vbBlue End With On Error GoTo 0 End Sub This changes font colors for the entire usedrange of a worksheet - you could use the HasFormula property of the Range object to determine if the cell contains a formula or not: Sub ColorCells2() With Sheet1.Range("A3") If .HasFormula Then .Font.Color = vbBlack Else .Font.Color = vbBlue End If End With End Sub -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
change font colour if cell contains function - programmatically
Thanks Rob,
That solution works well. I've never used Iif before. "Rob van Gelder" wrote in message ... Here's the code way: Sub test() With Cells(3, 3) .Interior.Color = IIf(.HasFormula, vbBlue, vbBlack) End With End Sub There is also a Named Range method, which is kind of dodgy and crashes XL97 users under specific conditions - on my website "IsFormula" -- Rob van Gelder - http://www.vangelder.co.nz/excel "fitful_thought" wrote in message ... How do I get the font color to be black if cells(3,3) contains "=today()" but to be blue if cells(3,3) contains (for example) "30 Oct 2004"? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
textBox font colour the same as cell font colour???????? | Excel Discussion (Misc queries) | |||
How to change font colour in unlocked cell of protected sheet | Excel Discussion (Misc queries) | |||
formula to change font or cell colour | Excel Worksheet Functions | |||
how do I change cell colour to show function used | Excel Worksheet Functions | |||
Change font colour | Excel Discussion (Misc queries) |