Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
textBox font colour the same as cell font colour???????? Sophie Excel Discussion (Misc queries) 4 February 13th 09 10:15 AM
How to change font colour in unlocked cell of protected sheet Michelle Excel Discussion (Misc queries) 2 September 16th 08 05:58 PM
formula to change font or cell colour Dave Excel Worksheet Functions 3 November 25th 07 08:25 PM
how do I change cell colour to show function used stufree Excel Worksheet Functions 3 October 31st 07 10:13 AM
Change font colour [email protected] Excel Discussion (Misc queries) 3 December 23rd 06 07:07 PM


All times are GMT +1. The time now is 02:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"