Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default cell color condition

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 133
Default cell color condition

On Jan 21, 2:53 pm, Can-Ann wrote:
Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance


You have to examine the ColorIndex property so do something like:

Sub CheckColor()
Dim cell as Range

For Each cell in Range("Whatever")
If cell.Interior.ColorIndex = "the Index Number" Then
do something
End If
Next

End Sub

You can find the index numbers for the color palette using help on the
ColorIndex property.

Although it may be easier just evaluating the cell using the same
conditions that colored it red in the first place

SteveM
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default cell color condition

I am going to assume that you mean the interior color of the cell, since it
does not have a foreground property.

If the cell was colored using the conditional format method:

Sub findColorRed()
If ActiveCell.FormatConditions(1).Interior.ColorIndex = 3 Then
'Put your code here
End If
End Sub

If the cell was colored using regular format method:

Sub findColorRed()
If ActiveCell.Interior.ColorIndex = 3 Then
'Put your code here
End If
End Sub

"Can-Ann" wrote:

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default cell color condition

If this is redundant ignore it. I don't see my original postl

There are two condidtions that can color the cell. If it is
colored by conditional format then:

Sub findColorRed()
If ActiveCell.FormatConditions(1).Interior.ColorIndex = 3 Then
' Your code here
End If
End Sub

If it is colored by regular format then:

Sub findColorRed()
If ActiveCell.Interior.ColorIndex = 3 Then
' Your code here
End If
End Sub




"Can-Ann" wrote:

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default cell color condition

If you already have the sub written (Sub MySub() ..... End sub) then the
following sub should do what you want or at least point you in the right
direction.

sub Demo()

If Range("A1").interior.colorindex = 3 then call MySub

End Sub


"Can-Ann" wrote:

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default cell color condition

try this:

If ActiveCell.Interior.ColorIndex = 3 Then
MsgBox "the selected cell has red background", vbOKOnly
End If

if it was helpfull please press yes.

greatings from Israel

"Can-Ann" wrote:

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default cell color condition

Try using conditional formatting.

M

"Can-Ann" wrote:

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default cell color condition

I used this to figure out the colors on a sheet I set up

Sub test()
Dim r As Range
For Each r In ActiveSheet.UsedRange
Debug.Print r.Address, r.Interior.ColorIndex, r.Font.Color
Next r
End Sub

But you'll have to check for yourself.

I believe what you want is
If ActiveCell.font.color = 255 then

end if

--
HTH,
Barb Reinhardt



"Can-Ann" wrote:

Using Office 2007
I want to run a specific routine if a cell foreground is red.
Can anyone show me what the formula would be.
Thanks in Advance

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
How can I automatically color a cell based upon a condition being RBober2 Excel Worksheet Functions 4 September 26th 09 09:14 PM
Is there a way to color a cell if it meets specific condition Sekhar Excel Discussion (Misc queries) 8 November 16th 08 06:34 PM
counting cell by color and condition Mark Excel Discussion (Misc queries) 1 April 22nd 07 04:56 PM
IF statement and color formatting for cell B1 for condition in A1 Rossta Excel Worksheet Functions 1 July 27th 06 12:37 AM
Using cell color as condition in equation John31 Excel Programming 2 January 7th 04 08:49 PM


All times are GMT +1. The time now is 04:51 AM.

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

About Us

"It's about Microsoft Excel"