Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 231
Default Cond Format - 7 conditions

Does anyone know how to set more than 3 conditional formats? I want the user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a specific
color. I would have up to 7 different color shades.

Thanks,

Sarah
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Cond Format - 7 conditions



Here is some VBA code (courtesy of Bob Phillips) which will
allow you to code more than 3 conditions:


'-----------------------------------------------------------------
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


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


HTH



"Sarah" wrote:

Does anyone know how to set more than 3 conditional formats? I want the user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a specific
color. I would have up to 7 different color shades.

Thanks,

Sarah

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Cond Format - 7 conditions

Example.


'-----------------------------------------------------------------
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

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Sarah" wrote in message
...
Does anyone know how to set more than 3 conditional formats? I want the
user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a
specific
color. I would have up to 7 different color shades.

Thanks,

Sarah



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 231
Default Cond Format - 7 conditions

That worked great, but once I import the Excel worksheet into MS Access and
then export it back out to my Excel template with the code you supplied, I
don't get the colors in the cell unless I go into each cell and hit enter.
How can they automatically show the color with out me having to do this?

Thanks,

Sarah

"Toppers" wrote:



Here is some VBA code (courtesy of Bob Phillips) which will
allow you to code more than 3 conditions:


'-----------------------------------------------------------------
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


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


HTH



"Sarah" wrote:

Does anyone know how to set more than 3 conditional formats? I want the user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a specific
color. I would have up to 7 different color shades.

Thanks,

Sarah

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Cond Format - 7 conditions

The code (worksheet event) does NOT work if you copy/paste (import) data: it
only works if the data is entered manually. Hence it works when you hit enter
as this triggers the worksheet event code.

The only option I can think of is to write code which will loop through ALL
cells in your range and set the conditional format.

"Sarah" wrote:

That worked great, but once I import the Excel worksheet into MS Access and
then export it back out to my Excel template with the code you supplied, I
don't get the colors in the cell unless I go into each cell and hit enter.
How can they automatically show the color with out me having to do this?

Thanks,

Sarah

"Toppers" wrote:



Here is some VBA code (courtesy of Bob Phillips) which will
allow you to code more than 3 conditions:


'-----------------------------------------------------------------
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


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


HTH



"Sarah" wrote:

Does anyone know how to set more than 3 conditional formats? I want the user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a specific
color. I would have up to 7 different color shades.

Thanks,

Sarah



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 231
Default Cond Format - 7 conditions

Thank you. I tried that and it worked. You're good!

"Toppers" wrote:

The code (worksheet event) does NOT work if you copy/paste (import) data: it
only works if the data is entered manually. Hence it works when you hit enter
as this triggers the worksheet event code.

The only option I can think of is to write code which will loop through ALL
cells in your range and set the conditional format.

"Sarah" wrote:

That worked great, but once I import the Excel worksheet into MS Access and
then export it back out to my Excel template with the code you supplied, I
don't get the colors in the cell unless I go into each cell and hit enter.
How can they automatically show the color with out me having to do this?

Thanks,

Sarah

"Toppers" wrote:



Here is some VBA code (courtesy of Bob Phillips) which will
allow you to code more than 3 conditions:


'-----------------------------------------------------------------
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


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


HTH



"Sarah" wrote:

Does anyone know how to set more than 3 conditional formats? I want the user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a specific
color. I would have up to 7 different color shades.

Thanks,

Sarah

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Cond Format - 7 conditions

Pleased to know it provided a satisfactory solution. Thank you for the
feedback.

"Sarah" wrote:

Thank you. I tried that and it worked. You're good!

"Toppers" wrote:

The code (worksheet event) does NOT work if you copy/paste (import) data: it
only works if the data is entered manually. Hence it works when you hit enter
as this triggers the worksheet event code.

The only option I can think of is to write code which will loop through ALL
cells in your range and set the conditional format.

"Sarah" wrote:

That worked great, but once I import the Excel worksheet into MS Access and
then export it back out to my Excel template with the code you supplied, I
don't get the colors in the cell unless I go into each cell and hit enter.
How can they automatically show the color with out me having to do this?

Thanks,

Sarah

"Toppers" wrote:



Here is some VBA code (courtesy of Bob Phillips) which will
allow you to code more than 3 conditions:


'-----------------------------------------------------------------
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


'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


HTH



"Sarah" wrote:

Does anyone know how to set more than 3 conditional formats? I want the user
to be able to type in a number and date in a cell like so:

1 04/05/07

and based on the number in the left most position, shade the cell a specific
color. I would have up to 7 different color shades.

Thanks,

Sarah

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
Cond format with date Navy Nurse Excel Worksheet Functions 3 January 25th 07 04:36 AM
Whole Row Cond. Format Ripper Excel Discussion (Misc queries) 2 October 6th 06 08:21 PM
Cond format more than 3 colours Keith Excel Discussion (Misc queries) 3 August 10th 06 08:19 AM
cond format jim brown Excel Worksheet Functions 2 April 20th 06 01:20 PM
using a UDF in place of a cond. format, b/c I need 4, not three MatthewTap Excel Discussion (Misc queries) 5 December 13th 05 06:50 PM


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