NamedRange.FormatConditions Property

Definition

Gets a FormatConditions collection that represents all the conditional formats for the NamedRange control.

public:
 property Microsoft::Office::Interop::Excel::FormatConditions ^ FormatConditions { Microsoft::Office::Interop::Excel::FormatConditions ^ get(); };
public Microsoft.Office.Interop.Excel.FormatConditions FormatConditions { get; }
member this.FormatConditions : Microsoft.Office.Interop.Excel.FormatConditions
Public ReadOnly Property FormatConditions As FormatConditions

Property Value

A FormatConditions collection that represents all the conditional formats for the NamedRange control.

Examples

The following code example creates a NamedRange and then uses the FormatConditions property to alter the font in the NamedRange if the value in the NamedRange is less than the value of cell A1.

This example is for a document-level customization.

Microsoft.Office.Tools.Excel.NamedRange formatConditionsRange;
private void ModifyFormatConditions()
{
    formatConditionsRange = this.Controls.AddNamedRange(
        this.Range["B1"], "formatConditionsRange");
    this.Range["A1"].Value2 = 99000;
    this.formatConditionsRange.Value2 = 98052;

    // Set conditional formatting to alter the font if 
    // the formatConditionsRange value is less than the value in A1.
    Excel.FormatCondition condition1 =
        (Excel.FormatCondition)this.formatConditionsRange.FormatConditions.Add(
        Excel.XlFormatConditionType.xlCellValue,
        Excel.XlFormatConditionOperator.xlLess, "=$a$1");

    condition1.Font.Bold = true;
    condition1.Font.Color = 0xFF00;
}
Private formatConditionsRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub ModifyFormatConditions()
    formatConditionsRange = Me.Controls.AddNamedRange( _
        Me.Range("B1"), "formatConditionsRange")
    Me.Range("A1").Value2 = 99000
    Me.formatConditionsRange.Value2 = 98052

    ' Set conditional formatting to alter the font if 
    ' the formatConditionsRange value is less than the value in A1.
    Dim condition1 As Excel.FormatCondition = _
        Me.formatConditionsRange.FormatConditions.Add( _
        Excel.XlFormatConditionType.xlCellValue, _
        Excel.XlFormatConditionOperator.xlLess, "=$a$1", )

    condition1.Font.Bold = True
    condition1.Font.Color = &HFF00
End Sub

Applies to