A DataValidation object represents a rule for validating data entered in cells. The rule may be applied to a cell or a set of cells. The Workbook class contains several CreateDataValidation methods for creating DataValidation objects. To apply a DataValidation object to a cell or group of cells, use Area.SetDataValidation or Range.SetDataValidation.

 public sealed class DataValidation
Public NotInheritable Class DataValidation

In Microsoft Excel, data validation rules are created through the Data Validation dialog. To open this dialog, open the Data menu and select Validation.


          ExcelApplication xlw = new ExcelApplication();
          Workbook wb = xlw.Create();

          //--- Create a data validation rule:
          DataValidation dv = wb.CreateDataValidation(
               DataValidation.ValidationType.WholeNumber,
               DataValidation.ComparisonType.Between,
               "=1", "=100");
          String formula = "Sheet1!A2:F33 Sheet2!A5:D15";

          //--- Apply the rule to a Range:
          wb.CreateRange(formula).SetDataValidation(dv);
        

          Dim xlw As New ExcelApplication()
          Dim wb As Workbook = xlw.Create()

          '--- Create a data validation rule:
          Dim dv As DataValidation = wb.CreateDataValidation( _
               DataValidation.ValidationType.WholeNumber, _
               DataValidation.ComparisonType.Between, _
               "=1", "=100")
          Dim formula As String = "Sheet1!A2:F33 Sheet2!A5:D15"

          '--- Apply the rule to a Range:
          wb.CreateRange(formula).SetDataValidation(dv)
        

Name

Description

AllowedType

Comparison

ErrorAlert

ErrorAlertStyle

ErrorAlertTitle

IgnoreBlanks

InputMessage

MinimumValue

MaximumValue

ShowErrorAlert

ShowInputMessage

Title

UseListDropdown

Name

Description

Clear()

SetAllowedType(ValidationType, ComparisonType, Object)

SetAllowedType(ValidationType, ComparisonType, Object, Object)

SetAllowedType(ValidationType, Object)

Name

Description

ComparisonType

ErrorAlertStyleType

ValidationType