ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select Case for Conditional Formatting (https://www.excelbanter.com/excel-programming/287615-select-case-conditional-formatting.html)

RonS

Select Case for Conditional Formatting
 
I've tried using the following code or more than three conditional formats, but it doesn't work

Basically I want the background color to show red, green, yellow, or blue if the text in a cell says the same thing

"Red" text would = red backgroun
"Blue" text = blue backgroun

Any hints you can give me would be much apprepriated - Thank

***** - five stars to anyone willing to give some feedbac

Private Sub Worksheet_Calculate(
Dim oCell As Rang
For Each oCell In Range("BF261:BF276"
Select Case oCell.Valu
Case Is = Re
oCell.Interior.Pattern = xlColorIndexNon
oCell.Interior.PatternColorIndex =
Case Is = Blu
oCell.Interior.Pattern = xlColorIndexNon
oCell.Interior.PatternColorIndex =
Case Is = Gree
oCell.Interior.Pattern = xlColorIndexNon
oCell.Interior.PatternColorIndex =
Case Is = Ambe
oCell.Interior.Pattern = xlColorIndexNon
oCell.Interior.PatternColorIndex =
Case Is = Complet
oCell.Interior.Pattern = xlColorIndexNon
oCell.Interior.PatternColorIndex = 3
End Selec
Next oCel
End Su






Heiko

Select Case for Conditional Formatting
 
Instead of

Case Is = Red

use

Case "Red"



"?B?Um9uUw==?=" wrote:

I've tried using the following code or more than three conditional formats, but it doesn't work.

Basically I want the background color to show red, green, yellow, or blue if the text in a cell says the same thing.

"Red" text would = red background
"Blue" text = blue backgroung

Any hints you can give me would be much apprepriated - Thanks

***** - five stars to anyone willing to give some feedback


Private Sub Worksheet_Calculate()
Dim oCell As Range
For Each oCell In Range("BF261:BF276")
Select Case oCell.Value
Case Is = Red
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 3
Case Is = Blue
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 5
Case Is = Green
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 3
Case Is = Amber
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 6
Case Is = Complete
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 39
End Select
Next oCell
End Sub







Don Guillett[_4_]

Select Case for Conditional Formatting
 
Try
Private Sub Worksheet_Calculate()
Dim oCell As Range
For Each oCell In Range("B2:B27")
Select Case UCase(oCell)
Case "RED"
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.ColorIndex = 3
Case "BLUE"
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.ColorIndex = 5
Case "GREEN"
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.ColorIndex = 3
Case "AMBER"
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.ColorIndex = 6
Case "COMPLETE"
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.ColorIndex = 39
End Select
Next oCell
End Sub
====
Here's another I did for someone a couple of days ago

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 2 Then Exit Sub
x = ActiveCell.Row
Set myrng = Range(Cells(x, "e"), Cells(x, "i"))
Select Case UCase(Target)
Case "ES", "NQ", "AB", "YM": myrng.NumberFormat = "###0.00"
Case "ZB": myrng.NumberFormat = "# ??/32"
Case "EC", "ED": myrng.NumberFormat = "0.0000"
Case "JY": myrng.NumberFormat = "##0.00"
End Select
Cells(x, "G").NumberFormat = "0.000000000000000"
End Sub


--
Don Guillett
SalesAid Software

"RonS" wrote in message
...
I've tried using the following code or more than three conditional

formats, but it doesn't work.

Basically I want the background color to show red, green, yellow, or blue

if the text in a cell says the same thing.

"Red" text would = red background
"Blue" text = blue backgroung

Any hints you can give me would be much apprepriated - Thanks

***** - five stars to anyone willing to give some feedback


Private Sub Worksheet_Calculate()
Dim oCell As Range
For Each oCell In Range("BF261:BF276")
Select Case oCell.Value
Case Is = Red
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 3
Case Is = Blue
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 5
Case Is = Green
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 3
Case Is = Amber
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 6
Case Is = Complete
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 39
End Select
Next oCell
End Sub








Don Guillett[_4_]

Select Case for Conditional Formatting
 
OOPS!
Forgot to mention that you must also put the formula
=NOW()
anywhere on your sheet to force calculation.

--
Don Guillett
SalesAid Software

"RonS" wrote in message
...
I've tried using the following code or more than three conditional

formats, but it doesn't work.

Basically I want the background color to show red, green, yellow, or blue

if the text in a cell says the same thing.

"Red" text would = red background
"Blue" text = blue backgroung

Any hints you can give me would be much apprepriated - Thanks

***** - five stars to anyone willing to give some feedback


Private Sub Worksheet_Calculate()
Dim oCell As Range
For Each oCell In Range("BF261:BF276")
Select Case oCell.Value
Case Is = Red
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 3
Case Is = Blue
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 5
Case Is = Green
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 3
Case Is = Amber
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 6
Case Is = Complete
oCell.Interior.Pattern = xlColorIndexNone
oCell.Interior.PatternColorIndex = 39
End Select
Next oCell
End Sub









All times are GMT +1. The time now is 08:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com