#1   Report Post  
Posted to microsoft.public.excel.misc
qwerty
 
Posts: n/a
Default CONDITIONAL FORMAT

is there any way to have more than 3 conditional formats or something like
doing it by formula?
thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default CONDITIONAL FORMAT

This can be accomplished by using the worksheet change event. The following
macro monitors changes in A1:A10 and set the background color:

Sub Worksheet_Change(ByVal Target As Excel.Range)
If Intersect(Range("A1:A10"), Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
Target.Select
i = Selection.Value
With Selection.Interior
.ColorIndex = i
.Pattern = xlSolid
End With
Application.EnableEvents = True
End Sub

The sample macro only works with integers and assigns colors based upon the
integers. You could modify it to operate in a more general way.
__________________Have a good day!
Gary's Student


"qwerty" wrote:

is there any way to have more than 3 conditional formats or something like
doing it by formula?
thanks in advance

  #3   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben
 
Posts: n/a
Default CONDITIONAL FORMAT

qwerty

John McGimpsey's site shows how to have up to 6 CF on font color per cell.

http://www.mcgimpsey.com/excel/conditional6.html

Otherwise a select case worksheet_change event is needed.

A couple of examples................

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("D:D"))
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 = "A": Num = 10 'green
Case Is = "B": Num = 1 'black
Case Is = "C": Num = 5 'blue
Case Is = "D": Num = 7 'magenta
Case Is = "E": Num = 46 'orange
Case Is = "F": Num = 3 'red
End Select
'Apply the color
Rng.Interior.ColorIndex = Num
Next Rng
endit:
Application.EnableEvents = True
End Sub


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
For Each Rng In vRngInput
'Determine the color
Select Case Rng.Value
Case Is <= 0: Num = 10 'green
Case 0 To 5: Num = 1 'black
Case 5 To 10: Num = 5 'blue
Case 10 To 15: Num = 7 'magenta
Case 15 To 20: Num = 46 'orange
Case Is 20: Num = 3 'red
End Select
'Apply the color
Rng.Font.ColorIndex = Num
Next Rng
End Sub

Right-click on the sheet tab and "View Code".

Paste one of the above into that module.


Gord Dibben Excel MVP

On Wed, 16 Nov 2005 06:30:08 -0800, qwerty wrote:

is there any way to have more than 3 conditional formats or something like
doing it by formula?
thanks in advance


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
Data Validation or Conditional Format (or combo of) Scott Excel Worksheet Functions 3 November 3rd 05 03:57 PM
Conditional format numbers PiPPo Excel Worksheet Functions 5 October 18th 05 05:03 AM
Cell Format Changes When Data Is Entered - Not Conditional Formatt SundanceKidLudwig Excel Worksheet Functions 2 September 30th 05 02:07 PM
Conditional format of minimum number MaggieMagill Excel Worksheet Functions 6 September 25th 05 11:36 PM
Conditional Format Question DougS Excel Worksheet Functions 3 May 3rd 05 01:36 AM


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