Conditional Formatting Advanced

Custom Formula Conditional Formatting

Create advanced conditional formatting rules using custom formulas

13 views

Perfect For:

  • Complex conditions
  • Multi-criteria highlighting
  • Advanced validation
VBA Code
Sub CustomFormulaFormatting()
    Dim dataRange As Range
    Dim formulaCondition As FormatCondition
    Dim formula As String

    ' Select the data range
    Set dataRange = Application.InputBox("Select range for custom formatting:", Type:=8)

    If dataRange Is Nothing Then Exit Sub

    ' Get custom formula from user
    formula = InputBox("Enter formula (use relative references, e.g., =AND(A1>100, B1<50)):", "Custom Formula")

    If formula = "" Then Exit Sub

    ' Clear existing conditional formatting
    dataRange.FormatConditions.Delete

    ' Add custom formula condition
    Set formulaCondition = dataRange.FormatConditions.Add( _
        Type:=xlExpression, _
        Formula1:=formula)

    ' Format cells that meet the condition
    With formulaCondition
        .Interior.Color = RGB(198, 224, 180)  ' Light green background
        .Font.Color = RGB(56, 87, 35)         ' Dark green text
        .Font.Bold = True
    End With

    MsgBox "Custom conditional formatting applied!"
End Sub

Related Topics

formulas advanced custom complex conditions

Need Custom VBA Solutions?

Our AI-powered VBA generator can create custom code tailored to your specific requirements in seconds.

Generate Custom VBA Code

Related Templates

More VBA templates in the same category

Beginner

Highlight Duplicate Values

Automatically highlight duplicate values in a range with conditional formatting

View Template