![]() |
Override conditional formatting with code
Does anyone know how to override conditional formatiing with code?
Thanks, Sarah |
Override conditional formatting with code
If you mean use code for CF then see example below:
----------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) '----------------------------------------------------------------- Const WS_RANGE As String = "H1:H10" 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 'etc. 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. "Sarah" wrote: Does anyone know how to override conditional formatiing with code? Thanks, Sarah |
Override conditional formatting with code
Conditional formatting overrides regular formatting. So the only way to
change the formatting that conditional formatting creates is to change the conditional formating rules or the conditional formatting format. To get an idea of the code you'd use to do that record a macro as you change it manually. -- Jim "Sarah" wrote in message ... Does anyone know how to override conditional formatiing with code? Thanks, Sarah |
Override conditional formatting with code
That worked. Thanks.
"Toppers" wrote: If you mean use code for CF then see example below: ----------------------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Range) '----------------------------------------------------------------- Const WS_RANGE As String = "H1:H10" 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 'etc. 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. "Sarah" wrote: Does anyone know how to override conditional formatiing with code? Thanks, Sarah |
Override conditional formatting with code
Thanks for the clarification. Now I understand how it works.
"Jim Rech" wrote: Conditional formatting overrides regular formatting. So the only way to change the formatting that conditional formatting creates is to change the conditional formating rules or the conditional formatting format. To get an idea of the code you'd use to do that record a macro as you change it manually. -- Jim "Sarah" wrote in message ... Does anyone know how to override conditional formatiing with code? Thanks, Sarah |
All times are GMT +1. The time now is 07:03 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com