Adds data validation to the specified range.
Namespace: Microsoft.Office.Interop.Excel
Assembly: Microsoft.Office.Interop.Excel (in microsoft.office.interop.excel.dll)
Dim <span id="parameterToolTip" class="tip" tabindex="0">Type</span> As XlDVType
Dim <span id="parameterToolTip" class="tip" tabindex="0">AlertStyle</span> As Object
Dim <span id="parameterToolTip" class="tip" tabindex="0">Operator</span> As Object
Dim <span id="parameterToolTip" class="tip" tabindex="0">Formula1</span> As Object
Dim <span id="parameterToolTip" class="tip" tabindex="0">Formula2</span> As Object
Dim validation1 As Validation
validation1.Add(<span id="parameterToolTip" class="tip" tabindex="0">Type</span>, <span id="parameterToolTip" class="tip" tabindex="0">AlertStyle</span>, <span id="parameterToolTip" class="tip" tabindex="0">Operator</span>, <span id="parameterToolTip" class="tip" tabindex="0">Formula1</span>, <span id="parameterToolTip" class="tip" tabindex="0">Formula2</span>)
Sub Add( _
<InAttribute()> ByVal Type As XlDVType, _
<InAttribute()> Optional ByVal AlertStyle As Object, _
<InAttribute()> Optional ByVal Operator As Object, _
<InAttribute()> Optional ByVal Formula1 As Object, _
<InAttribute()> Optional ByVal Formula2 As Object _
)
void Add(
[In] XlDVType Type,
[In, Optional] object AlertStyle,
[In, Optional] object Operator,
[In, Optional] object Formula1,
[In, Optional] object Formula2
);
public: Void Add(
XlDVType^ Type,
Object^ AlertStyle,
Object^ Operator,
Object^ Formula1,
Object^ Formula2
);
public void Add(
/*in*/XlDVType Type,
/*in*/System.Object AlertStyle,
/*in*/System.Object Operator,
/*in*/System.Object Formula1,
/*in*/System.Object Formula2
);
function Add(
Type : XlDVType,
AlertStyle : Object,
Operator : Object,
Formula1 : Object,
Formula2 : Object
);
Parameters
- Type
Required XlDVType. The validation type.
- AlertStyle
Optional Object. The validation alert style. Can be one of the following XlDVAlertStyle constants: xlValidAlertInformation, xlValidAlertStop, or xlValidAlertWarning.
- Operator
Optional Object. The data validation operator. Can be one of the following XlFormatConditionOperator constants: xlBetween, xlEqual, xlGreater, xlGreaterEqual, xlLess, xlLessEqual, xlNotBetween, or xlNotEqual.
- Formula1
Optional Object. The first part of the data validation equation.
- Formula2
Optional Object. The second part of the data validation when Operator is xlBetween or xlNotBetween (otherwise, this argument is ignored).
The Add method requires different arguments, depending on the validation type, as shown in the following table.
| Validation type | Arguments |
| xlValidateCustom | Formula1 is required; Formula2 is ignored. Formula1 must contain an expression that evaluates to True when data entry is valid and False when data entry is invalid. |
| xlInputOnly | AlertStyle, Formula1, or Formula2 are used. |
| xlValidateList | Formula1 is required; Formula2 is ignored. Formula1 must contain either a comma-delimited list of values or a worksheet reference to this list. |
| xlValidateWholeNumber, xlValidateDate, xlValidateDecimal, xlValidateTextLength, or xlValidateTime | One of either Formula1 or Formula2 must be specified, or both may be specified. |
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Development Platforms
Windows XP Home Edition, Windows XP Professional, Windows Server 2003, and Windows 2000Target Platforms