Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default 5 or more Conditonal formats

Hi,

I need to add more than 5 conditional formats to my spreadsheet. Joel
responded to me with the following but unforunately my VB is not the
greatest. Where do i put in my arguments etc to make it go red or blue etc?



Thsi si a very popular question. It is asked a few times a week. Here is
the answer somebody provided earlier this week. It shows four conditions but
can easily be changes to havve many more conditions Just add more case
statements to the function.

-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 1: .Interior.ColorIndex = 3 'red
Case 2: .Interior.ColorIndex = 6 'yellow
Case 3: .Interior.ColorIndex = 5 'blue
Case 4: .Interior.ColorIndex = 10 'green
End Select
End With
End If


ws_exit:
Application.EnableEvents = True
End Sub



"Hawksby" wrote:

Is there a way of having 5 or more conditional formats?


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 5 or more Conditonal formats

This section does the work:

Case 1: .Interior.ColorIndex = 3 'red
Case 2: .Interior.ColorIndex = 6 'yellow
Case 3: .Interior.ColorIndex = 5 'blue
Case 4: .Interior.ColorIndex = 10 'green

So you can change it the way you like:

Case "some text value": .Interior.ColorIndex = 3 'red
Case "something": .Interior.ColorIndex = 6 'yellow
Case "another thing": .Interior.ColorIndex = 5 'blue
Case 12344: .Interior.ColorIndex = 10 'green
case "that was a real number above": .interior.colorindex = 23

If you're not sure what the colors should be,
then add a new worksheet
record a macro when you change some background colors
Stop the macro

look at the code to see what excel recorded.

Hawksby wrote:

Hi,

I need to add more than 5 conditional formats to my spreadsheet. Joel
responded to me with the following but unforunately my VB is not the
greatest. Where do i put in my arguments etc to make it go red or blue etc?

Thsi si a very popular question. It is asked a few times a week. Here is
the answer somebody provided earlier this week. It shows four conditions but
can easily be changes to havve many more conditions Just add more case
statements to the function.

-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 1: .Interior.ColorIndex = 3 'red
Case 2: .Interior.ColorIndex = 6 'yellow
Case 3: .Interior.ColorIndex = 5 'blue
Case 4: .Interior.ColorIndex = 10 'green
End Select
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

"Hawksby" wrote:

Is there a way of having 5 or more conditional formats?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 16
Default 5 or more Conditonal formats

Dave,

Do i need to change any other part of the code? as i'm having difficulty in
getting it to work

"Hawksby" wrote:

Hi,

I need to add more than 5 conditional formats to my spreadsheet. Joel
responded to me with the following but unforunately my VB is not the
greatest. Where do i put in my arguments etc to make it go red or blue etc?



Thsi si a very popular question. It is asked a few times a week. Here is
the answer somebody provided earlier this week. It shows four conditions but
can easily be changes to havve many more conditions Just add more case
statements to the function.

-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 1: .Interior.ColorIndex = 3 'red
Case 2: .Interior.ColorIndex = 6 'yellow
Case 3: .Interior.ColorIndex = 5 'blue
Case 4: .Interior.ColorIndex = 10 'green
End Select
End With
End If


ws_exit:
Application.EnableEvents = True
End Sub



"Hawksby" wrote:

Is there a way of having 5 or more conditional formats?


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 5 or more Conditonal formats

Maybe...

You have to specify the cells that get changed in this line:

Const WS_RANGE As String = "H1:H10"

And make sure you put the code behind the worksheet that should have this
behavior.

Rightclick on the worksheet tab, select view code and make sure your code is
there. Delete other versions if you pasted them elsewhere.

And if this doesn't help, you're gonna have to explain what you tried and what
failed.

Hawksby wrote:

Dave,

Do i need to change any other part of the code? as i'm having difficulty in
getting it to work

"Hawksby" wrote:

Hi,

I need to add more than 5 conditional formats to my spreadsheet. Joel
responded to me with the following but unforunately my VB is not the
greatest. Where do i put in my arguments etc to make it go red or blue etc?



Thsi si a very popular question. It is asked a few times a week. Here is
the answer somebody provided earlier this week. It shows four conditions but
can easily be changes to havve many more conditions Just add more case
statements to the function.

-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10" '<=== change to suit


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Select Case .Value
Case 1: .Interior.ColorIndex = 3 'red
Case 2: .Interior.ColorIndex = 6 'yellow
Case 3: .Interior.ColorIndex = 5 'blue
Case 4: .Interior.ColorIndex = 10 'green
End Select
End With
End If


ws_exit:
Application.EnableEvents = True
End Sub



"Hawksby" wrote:

Is there a way of having 5 or more conditional formats?



--

Dave Peterson
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
Conditonal formatting Hawksby Excel Discussion (Misc queries) 2 March 9th 07 01:49 PM
Conditonal Formula flyers5182 Excel Discussion (Misc queries) 7 February 5th 07 09:17 PM
Multiple Conditonal Formats Dave Excel Discussion (Misc queries) 4 November 2nd 06 11:47 PM
Conditonal Formatting Matt Excel Discussion (Misc queries) 3 April 21st 06 07:42 PM
Nested Ifs In Conditonal Formats ANDYPAND New Users to Excel 1 August 2nd 05 04:25 PM


All times are GMT +1. The time now is 05:32 PM.

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"