• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to "convert" Conditional Format in VBA?

Eloise T

Active Member
This is the Conditional Format specifications that I need to duplicate in VBA code:
upload_2018-12-24_17-31-38.png


This is what I've got. It doesn't error out, but it doesn't work either.
Code:
With Ws.Range("D3:D250")
     .FormatConditions.Add Type:=xlExpression, Formula1:=">=6"
End With


The problem as I see it is indicating the Cell Value in the VBA code ( Formula1:=">=6" )

Thanks for your help in advance.
 
Try this:
Code:
With ws.Range("D3:D250")
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
        , Formula1:="=6"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 0
        .Gradient.ColorStops.Clear
    End With
    With .FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    With .FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
        .Color = 14171890
        .TintAndShade = 0
    End With
    .FormatConditions(1).StopIfTrue = False
End With

And hats off to your signature text. ;)Loved it. :awesome:

All the best! Merry Xmas.

BR/Ajesh
 
Last edited:
Try this:
Code:
With ws.Range("D3:D250")
    .FormatConditions.Add Type:=xlCellValue, Operator:=xlGreaterEqual _
        , Formula1:="=6"
    .FormatConditions(.FormatConditions.Count).SetFirstPriority
    With .FormatConditions(1).Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 0
        .Gradient.ColorStops.Clear
    End With
    With .FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    With .FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
        .Color = 14171890
        .TintAndShade = 0
    End With
    .FormatConditions(1).StopIfTrue = False
End With

And hats off to your signature text. ;)Loved it. :awesome:

All the best! Merry Xmas.

BR/Ajesh
Outstanding design and results, BR/Ajesh!
 
Back
Top