LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Conditional formatting code wont work

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
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 - Not all colors work? PSS New Users to Excel 1 April 18th 08 11:49 PM
Will Conditional Formatting work? Lisa Excel Worksheet Functions 6 September 7th 07 03:04 PM
Will Conditional Formatting work? jennjenn Excel Worksheet Functions 2 August 1st 07 05:40 PM
Why wont this code work? Mark Stephens[_3_] Excel Programming 1 April 30th 05 07:01 PM
Conditional Formatting Work around? John Excel Worksheet Functions 2 October 29th 04 08:10 AM


All times are GMT +1. The time now is 11:20 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"