Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 60
Default Conditional Formatting--Need 4 conditions

I need to add a fourth condition to a column. I have already used 3 which is
apparently the limit that excel will allow. I have a column that contains
the text Red, Green, Yellow or Blue. I have set the conditional formatting
for Red, Green and yellow and everything works fine. I need to add an
additional conditional to turn the cell Blue if it contains the text Blue.
Can anyone help??????
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Conditional Formatting--Need 4 conditions

CB

The fourth condition could be the default color for those cells.

i.e. Set the 3 conditions for yellow, green and red and the default "no color"
is used for yellow.

Or dispense with CF and go to sheet event code if you choose.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "Red": Num = 3
Case Is = "Green": Num = 10
Case Is = "Yellow": Num = 6
Case Is = "Blue": Num = 5
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the above into that sheet module.

As written it works only on column A. Adjust to suit.


Gord Dibben MS Excel MVP

On Tue, 6 Feb 2007 07:34:00 -0800, CB wrote:

I need to add a fourth condition to a column. I have already used 3 which is
apparently the limit that excel will allow. I have a column that contains
the text Red, Green, Yellow or Blue. I have set the conditional formatting
for Red, Green and yellow and everything works fine. I need to add an
additional conditional to turn the cell Blue if it contains the text Blue.
Can anyone help??????


  #3   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 60
Default Conditional Formatting--Need 4 conditions

Gord,
Thanks for the answer. This works perfect. A couple of follow up question:
1-How can I color the text the same as the cell fill so the text is not seen?
2-Where can I find out what number point to which color?
Thanks again for your help.
Cheryl

"Gord Dibben" wrote:

CB

The fourth condition could be the default color for those cells.

i.e. Set the 3 conditions for yellow, green and red and the default "no color"
is used for yellow.

Or dispense with CF and go to sheet event code if you choose.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "Red": Num = 3
Case Is = "Green": Num = 10
Case Is = "Yellow": Num = 6
Case Is = "Blue": Num = 5
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the above into that sheet module.

As written it works only on column A. Adjust to suit.


Gord Dibben MS Excel MVP

On Tue, 6 Feb 2007 07:34:00 -0800, CB wrote:

I need to add a fourth condition to a column. I have already used 3 which is
apparently the limit that excel will allow. I have a column that contains
the text Red, Green, Yellow or Blue. I have set the conditional formatting
for Red, Green and yellow and everything works fine. I need to add an
additional conditional to turn the cell Blue if it contains the text Blue.
Can anyone help??????



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Conditional Formatting--Need 4 conditions

Add a line as below for font color to match background

'Apply the color
rng.Interior.ColorIndex = Num
' add this line rng.Font.ColorIndex = Num
Next rng

For a list of color indices see David McRitchie's site

http://www.mvps.org/dmcritchie/excel/colors.htm

Or run this macro to get a list on new worksheet.

Sub ListColorIndexes()
Dim Ndx As Long
Sheets.Add
For Ndx = 1 To 56
Cells(Ndx, 1).Interior.ColorIndex = Ndx
Cells(Ndx, 2).Value = Hex(ThisWorkbook.Colors(Ndx))
Cells(Ndx, 3).Value = Ndx
Next Ndx
End Sub


Gord

On Tue, 6 Feb 2007 11:15:01 -0800, CB wrote:

Gord,
Thanks for the answer. This works perfect. A couple of follow up question:
1-How can I color the text the same as the cell fill so the text is not seen?
2-Where can I find out what number point to which color?
Thanks again for your help.
Cheryl

"Gord Dibben" wrote:

CB

The fourth condition could be the default color for those cells.

i.e. Set the 3 conditions for yellow, green and red and the default "no color"
is used for yellow.

Or dispense with CF and go to sheet event code if you choose.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "Red": Num = 3
Case Is = "Green": Num = 10
Case Is = "Yellow": Num = 6
Case Is = "Blue": Num = 5
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the above into that sheet module.

As written it works only on column A. Adjust to suit.


Gord Dibben MS Excel MVP

On Tue, 6 Feb 2007 07:34:00 -0800, CB wrote:

I need to add a fourth condition to a column. I have already used 3 which is
apparently the limit that excel will allow. I have a column that contains
the text Red, Green, Yellow or Blue. I have set the conditional formatting
for Red, Green and yellow and everything works fine. I need to add an
additional conditional to turn the cell Blue if it contains the text Blue.
Can anyone help??????




  #5   Report Post  
Posted to microsoft.public.excel.misc
CB CB is offline
external usenet poster
 
Posts: 60
Default Conditional Formatting--Need 4 conditions

Perfect. Thanks So Much.


"Gord Dibben" wrote:

Add a line as below for font color to match background

'Apply the color
rng.Interior.ColorIndex = Num
' add this line rng.Font.ColorIndex = Num
Next rng

For a list of color indices see David McRitchie's site

http://www.mvps.org/dmcritchie/excel/colors.htm

Or run this macro to get a list on new worksheet.

Sub ListColorIndexes()
Dim Ndx As Long
Sheets.Add
For Ndx = 1 To 56
Cells(Ndx, 1).Interior.ColorIndex = Ndx
Cells(Ndx, 2).Value = Hex(ThisWorkbook.Colors(Ndx))
Cells(Ndx, 3).Value = Ndx
Next Ndx
End Sub


Gord

On Tue, 6 Feb 2007 11:15:01 -0800, CB wrote:

Gord,
Thanks for the answer. This works perfect. A couple of follow up question:
1-How can I color the text the same as the cell fill so the text is not seen?
2-Where can I find out what number point to which color?
Thanks again for your help.
Cheryl

"Gord Dibben" wrote:

CB

The fourth condition could be the default color for those cells.

i.e. Set the 3 conditions for yellow, green and red and the default "no color"
is used for yellow.

Or dispense with CF and go to sheet event code if you choose.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "Red": Num = 3
Case Is = "Green": Num = 10
Case Is = "Yellow": Num = 6
Case Is = "Blue": Num = 5
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the above into that sheet module.

As written it works only on column A. Adjust to suit.


Gord Dibben MS Excel MVP

On Tue, 6 Feb 2007 07:34:00 -0800, CB wrote:

I need to add a fourth condition to a column. I have already used 3 which is
apparently the limit that excel will allow. I have a column that contains
the text Red, Green, Yellow or Blue. I have set the conditional formatting
for Red, Green and yellow and everything works fine. I need to add an
additional conditional to turn the cell Blue if it contains the text Blue.
Can anyone help??????






  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Conditional Formatting--Need 4 conditions

Appreciate the feedback.

Just a note on colorindex numbers.

You may have modified a color or two in your workbook.

Excel uses the colorindex of the original color, not the modified one.

i.e. Default Yellow = 6

Default Yellow is RGB 255, 255, 0

Change to green with 0, 255, 150 and Excel still calls it index number 6


Gord

On Tue, 6 Feb 2007 14:10:00 -0800, CB wrote:

Perfect. Thanks So Much.


"Gord Dibben" wrote:

Add a line as below for font color to match background

'Apply the color
rng.Interior.ColorIndex = Num
' add this line rng.Font.ColorIndex = Num
Next rng

For a list of color indices see David McRitchie's site

http://www.mvps.org/dmcritchie/excel/colors.htm

Or run this macro to get a list on new worksheet.

Sub ListColorIndexes()
Dim Ndx As Long
Sheets.Add
For Ndx = 1 To 56
Cells(Ndx, 1).Interior.ColorIndex = Ndx
Cells(Ndx, 2).Value = Hex(ThisWorkbook.Colors(Ndx))
Cells(Ndx, 3).Value = Ndx
Next Ndx
End Sub


Gord

On Tue, 6 Feb 2007 11:15:01 -0800, CB wrote:

Gord,
Thanks for the answer. This works perfect. A couple of follow up question:
1-How can I color the text the same as the cell fill so the text is not seen?
2-Where can I find out what number point to which color?
Thanks again for your help.
Cheryl

"Gord Dibben" wrote:

CB

The fourth condition could be the default color for those cells.

i.e. Set the 3 conditions for yellow, green and red and the default "no color"
is used for yellow.

Or dispense with CF and go to sheet event code if you choose.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "Red": Num = 3
Case Is = "Green": Num = 10
Case Is = "Yellow": Num = 6
Case Is = "Blue": Num = 5
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the above into that sheet module.

As written it works only on column A. Adjust to suit.


Gord Dibben MS Excel MVP

On Tue, 6 Feb 2007 07:34:00 -0800, CB wrote:

I need to add a fourth condition to a column. I have already used 3 which is
apparently the limit that excel will allow. I have a column that contains
the text Red, Green, Yellow or Blue. I have set the conditional formatting
for Red, Green and yellow and everything works fine. I need to add an
additional conditional to turn the cell Blue if it contains the text Blue.
Can anyone help??????





  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Conditional Formatting--Need 4 conditions

Your solution works great for one set of conditions in a sheet, but is it
possible to make it work with multiple conditions? For example:

Range("a1:a10,a20:a30"))
Case Is = "": Num = 2 'white
Case Is = 0: Num = 38 'red
Case Is = 1: Num = 36 'yellow
Case Is = 2: Num = 35 'green
Case Is = 3: Num = 34 'blue

Range("b15:b30,b55:b60"))
Case Is = "": Num = 2 'white
Case Is < 90: Num = 38 'red
Case Is < 80: Num = 36 'yellow
Case Is < 70: Num = 35 'green
Case Is < 50: Num = 34 'blue

TIA.
"Gord Dibben" wrote:

CB

The fourth condition could be the default color for those cells.

i.e. Set the 3 conditions for yellow, green and red and the default "no color"
is used for yellow.

Or dispense with CF and go to sheet event code if you choose.

Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Num As Long
Dim rng As Range
Dim vRngInput As Variant
Set vRngInput = Intersect(Target, Range("A:A"))
If vRngInput Is Nothing Then Exit Sub
On Error GoTo endit
Application.EnableEvents = False
For Each rng In vRngInput
'Determine the color
Select Case rng.Value
Case Is = "Red": Num = 3
Case Is = "Green": Num = 10
Case Is = "Yellow": Num = 6
Case Is = "Blue": Num = 5
End Select
'Apply the color
rng.Interior.ColorIndex = Num
Next rng
endit:
Application.EnableEvents = True
End Sub

This is sheet event code. Right-click on the sheet tab and "View Code".

Copy/paste the above into that sheet module.

As written it works only on column A. Adjust to suit.


Gord Dibben MS Excel MVP

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 Formatting with 4 or more conditions Philipp Ehrenstein Excel Worksheet Functions 6 November 27th 06 05:39 PM
Conditional Formatting on more than "4" Conditions belly0fdesire Excel Discussion (Misc queries) 1 September 1st 05 10:41 PM
Conditional formatting wth more than 3 conditions Sue Excel Worksheet Functions 3 August 19th 05 10:26 PM
Conditional formatting: I have five conditions, how to do this? Danzguy Excel Discussion (Misc queries) 2 May 11th 05 08:21 AM
Conditional Formatting Error ddate Excel Worksheet Functions 0 May 5th 05 09:00 PM


All times are GMT +1. The time now is 09:11 PM.

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"