Validation.Add (Excel)
Adds data validation to the specified range.
The Add method requires different arguments, depending on the validation type, as shown in the following table.
Add (Type, AlertStyle, Operator, Formula1, Formula2)
ActiveCell.Validation.Add Type:=xlValidateCustom
Arguments
The following argument is required
Type (XlDVType) - The validation type.
Possible values are
xlValidateCustom | Data is validated using an arbitrary formula. |
xlValidateDate | Date values. |
xlValidateDecimal | Numeric values. |
xlValidateInputOnly | Validate only when user changes the value. |
xlValidateList | Value must be present in a specified list. |
xlValidateTextLength | Length of text. |
xlValidateTime | Time values. |
xlValidateWholeNumber | Whole numeric values. |
Optional arguments
The following arguments are optional
AlertStyle (XlDVAlertStyle) - The validation alert style. Can be one of the following XlDVAlertStyle constants: xlValidAlertInformation, xlValidAlertStop, or xlValidAlertWarning.
Possible return values are xlValidAlertInformation - Information icon, xlValidAlertStop - Stop icon, xlValidAlertWarning - Warning icon.
Operator (XlFormatConditionOperator) - The data validation operator. Can be one of the following XlFormatConditionOperator constants: xlBetween, xlEqual, xlGreater, xlGreaterEqual, xlLess, xlLessEqual, xlNotBetween, or xlNotEqual.
Possible values are
xlBetween | Between. Can be used only if two formulas are provided. |
xlEqual | Equal. |
xlGreater | Greater than. |
xlGreaterEqual | Greater than or equal to. |
xlLess | Less than. |
xlLessEqual | Less than or equal to. |
xlNotBetween | Not between. Can be used only if two formulas are provided. |
xlNotEqual | Not equal. |
Formula1 - The first part of the data validation equation. Value must not exceed 255 characters
Formula2 (XlFormatConditionOperator) - The second part of the data validation equation when Operator is xlBetween or xlNotBetween (otherwise, this argument is ignored).
Possible values are
xlBetween | Between. Can be used only if two formulas are provided. |
xlEqual | Equal. |
xlGreater | Greater than. |
xlGreaterEqual | Greater than or equal to. |
xlLess | Less than. |
xlLessEqual | Less than or equal to. |
xlNotBetween | Not between. Can be used only if two formulas are provided. |
xlNotEqual | Not equal. |