Home |
Search |
Today's Posts |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You could try something like the following:
Public Sub ConditionalFill() Dim val As Long Dim nr1 As Long Dim nr2 As Long Dim nr3 As Long val = ActiveCell.Value nr1 = Range(ActiveWorkbook.Names("namedrange1")).Value nr2 = Range(ActiveWorkbook.Names("namedrange2")).Value nr3 = Range(ActiveWorkbook.Names("namedrange3")).Value Select Case True Case val nr1 And val < nr2 ActiveCell.Interior.ColorIndex = 6 Case val nr2 And val < nr3 ActiveCell.Interior.ColorIndex = 5 Case Else ActiveCell.Interior.ColorIndex = xlColorIndexNone End Select 'If val nr1 And val < nr2 Then ' ActiveCell.Interior.ColorIndex = 6 'ElseIf val nr2 And val < nr3 Then ' ActiveCell.Interior.ColorIndex = 5 'Else ' ActiveCell.Interior.ColorIndex = xlColorIndexNone 'End If End Sub Personally, I would use the If..ElseIf structure (commented out) instead of the Select Case. First, it's more intuitive to code, and second it's reportly faster. Also, the above code assumes Long for the cell value type - change that as need be. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Conditional Formatting - Not all colors work? | New Users to Excel | |||
Will Conditional Formatting work? | Excel Worksheet Functions | |||
Will Conditional Formatting work? | Excel Worksheet Functions | |||
Why wont this code work? | Excel Programming | |||
Conditional Formatting Work around? | Excel Worksheet Functions |