Partager via


FormatConditions.Add Method

Adds a new conditional format. Returns a FormatCondition object that represents the new conditional format.

Namespace: Microsoft.Office.Interop.Excel
Assembly: Microsoft.Office.Interop.Excel (in microsoft.office.interop.excel.dll)

Usage

'Utilisation
Dim Type As XlFormatConditionType
Dim Operator As Object
Dim Formula1 As Object
Dim Formula2 As Object
Dim returnValue As FormatCondition
Dim formatConditions1 As FormatConditions
returnValue = formatConditions1.Add(Type, Operator, Formula1, Formula2)

Syntax

'Déclaration
Function Add( _
    <InAttribute()> ByVal Type As XlFormatConditionType, _
    <InAttribute()> Optional ByVal Operator As Object, _
    <InAttribute()> Optional ByVal Formula1 As Object, _
    <InAttribute()> Optional ByVal Formula2 As Object _
) As FormatCondition
FormatCondition Add(
    [In] XlFormatConditionType Type, 
    [In, Optional] object Operator, 
    [In, Optional] object Formula1, 
    [In, Optional] object Formula2
);
public: FormatCondition^ Add(
    XlFormatConditionType^ Type, 
    Object^ Operator, 
    Object^ Formula1, 
    Object^ Formula2
);
public FormatCondition Add(
    /*in*/XlFormatConditionType Type, 
    /*in*/System.Object Operator, 
    /*in*/System.Object Formula1, 
    /*in*/System.Object Formula2
);
function Add(
     Type : XlFormatConditionType, 
     Operator : Object, 
     Formula1 : Object, 
     Formula2 : Object
) : FormatCondition;

Parameters

  • Type
    Required XlFormatConditionType. Specifies whether the conditional format is based on a cell value or an expression. Can be one of the following XlFormatConditionType constants:

    xlCellValue The conditional format is based on a cell value.

    xlExpression The conditional format is based on an expression.

  • Operator
    Optional Object. The conditional format operator. Can be one of the following XlFormatConditionOperator constants: xlBetween, xlEqual, xlGreater, xlGreaterEqual, xlLess, xlLessEqual, xlNotBetween, or xlNotEqual. If Type is xlExpression, the Operator argument is ignored.
  • Formula1
    Optional Object. The value or expression associated with the conditional format. Can be a constant value, a string value, a cell reference, or a formula.
  • Formula2
    Optional Object. The value or expression associated with the second part of the conditional format when Operator is xlBetween or xlNotBetween (otherwise, this argument is ignored). Can be a constant value, a string value, a cell reference, or a formula.

Remarks

You cannot define more than three conditional formats for a range. Use the Modify method to modify an existing conditional format, or use the Delete method to delete an existing format before adding a new one.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000

Target Platforms

See Also

Reference

FormatConditions Interface
Microsoft.Office.Interop.Excel Namespace

Other Resources

FormatConditions Members