Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IF Statement and Font Color

Is there a way to have an IF statement check a cell and do something
according to the color of the font?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 812
Default IF Statement and Font Color

Yes, with VBA (not IF worksheet function). An example:

Sub macro1()
If Sheets("Sheet1").Range("A1").Font.ColorIndex = 1 Then
Sheets("Sheet1").Range("B1") = "black"
ElseIf Sheets("Sheet1").Range("A1").Font.ColorIndex = 3 Then
Sheets("Sheet1").Range("B1") = "red"
ElseIf Sheets("Sheet1").Range("A1").Font.ColorIndex = 10 Then
Sheets("Sheet1").Range("B1") = "green"
End If

Hth,
Merjet


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default IF Statement and Font Color

in xl2003 and earlier, the interior color of a cell can be one of 56 values
or xlnone.

if activecell.Interior.ColorIndex = 3 then
' the cells interior is red

to see the Colors associated with the colorindex

Sub ShowColors()
for i = 1 to 56
cells(i,1).Interior.ColorIndex = i
cells(i,2).Value = i
Next
End Sub

Note that the user can create a custom palatte in a workbook and map
different colors to the 56 available colorindexes.

A good discussion of Excel and colors is at
http://www.mvps.org/dmcritchie/excel/colors.htm

--
Regards,
Tom Ogilvy


" wrote:

Is there a way to have an IF statement check a cell and do something
according to the color of the font?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default IF Statement and Font Color

Try something like the following:


If Range("A1").Font.ColorIndex = 3 Then ' red
MsgBox "Red Cell"
End If



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

wrote in message
oups.com...
Is there a way to have an IF statement check a cell and do something
according to the color of the font?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default IF Statement and Font Color

missed the "Font" part

If activecell.Font.ColorIndex = 3 then
' font color is red

Instead of xlNone for the interior of the cell, the setting is xlautomatic
(if you don't want to assign a color, but let excel set it based on the
color scheme).

--
Regards,
Tom Ogilvy




"Tom Ogilvy" wrote in message
...
in xl2003 and earlier, the interior color of a cell can be one of 56
values
or xlnone.

if activecell.Interior.ColorIndex = 3 then
' the cells interior is red

to see the Colors associated with the colorindex

Sub ShowColors()
for i = 1 to 56
cells(i,1).Interior.ColorIndex = i
cells(i,2).Value = i
Next
End Sub

Note that the user can create a custom palatte in a workbook and map
different colors to the 56 available colorindexes.

A good discussion of Excel and colors is at
http://www.mvps.org/dmcritchie/excel/colors.htm

--
Regards,
Tom Ogilvy


" wrote:

Is there a way to have an IF statement check a cell and do something
according to the color of the font?




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
Conditional Format for font color using font color Jim Excel Worksheet Functions 2 August 29th 09 11:54 AM
Changing Font color based on font type or size John Excel Discussion (Misc queries) 2 February 7th 08 12:50 AM
Formatting color and font to a logical statement result? STRAC Excel Worksheet Functions 7 January 17th 08 09:52 PM
can font color be controled in an IF statement Confused Rookie Excel Worksheet Functions 3 November 21st 07 05:25 PM
If statement to test font color Gary Excel Discussion (Misc queries) 5 May 24th 06 09:09 PM


All times are GMT +1. The time now is 09:49 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"