Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conditional Formatting with 4 or more conditions | Excel Worksheet Functions | |||
Conditional Formatting on more than "4" Conditions | Excel Discussion (Misc queries) | |||
Conditional formatting wth more than 3 conditions | Excel Worksheet Functions | |||
Conditional formatting: I have five conditions, how to do this? | Excel Discussion (Misc queries) | |||
Conditional Formatting Error | Excel Worksheet Functions |