Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() 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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Cond format with date | Excel Worksheet Functions | |||
Whole Row Cond. Format | Excel Discussion (Misc queries) | |||
Cond format more than 3 colours | Excel Discussion (Misc queries) | |||
cond format | Excel Worksheet Functions | |||
using a UDF in place of a cond. format, b/c I need 4, not three | Excel Discussion (Misc queries) |