Conditional formatting

kamalm

New Member
Joined
Jul 30, 2018
Messages
33
I have set conditional formatting at both of my column BA and BB. The cells will be filled in color if the values are in the range.

Code:
Columns("BA:BA").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
        Formula1:="=0.921", Formula2:="=0.931"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 5296274
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Columns("BB:BB").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
        Formula1:="=0.069", Formula2:="=0.079"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 5296274
        .TintAndShade = 0
    End With


What code I have to use to make the cells that are not in the range to be filled with other color ?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
The same code should work, just change
Columns("BA:BA").Select

to the range of cells/columns you want to change, and change the color number to the new color you want them.
 
Upvote 0
Try this which assumes that all values in both columns are always positive

What's happening
- clear prior CF
- apply CF colour2 to all cells in column containing values
- apply CF colour1 to all cells falling inside the designated range of vaues

Code:
Sub ConditionalFormattngOutsideRange()
    Dim c1 As String:       [COLOR=#ff0000]c1[/COLOR] = 5296274
    Dim c2 As String:       [COLOR=#000080]c2[/COLOR] = 99999999
    Columns("BA").Select
    With Selection
        .FormatConditions.Delete
        
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=0"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        .FormatConditions(1).Interior.Color = [COLOR=#000080]c2[/COLOR]
        
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=0.921", Formula2:="=0.931"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        .FormatConditions(1).Interior.Color = [COLOR=#ff0000]c1[/COLOR]
    End With
        
    Columns("BB").Select
    With Selection
        .FormatConditions.Delete
        
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, Formula1:="=0"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        .FormatConditions(1).Interior.Color = [COLOR=#000080]c2[/COLOR]
        
        .FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, Formula1:="=0.069", Formula2:="=0.079"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        .FormatConditions(1).Interior.Color = [COLOR=#ff0000]c1[/COLOR]
      
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top