# Modify Validation

Learn how to modify an existing validation rule applied to a cell or a range of cells in DsExcel with a sample code.

## Content





You can modify the validation rule for a cell range by using either of the two ways described below:

*   Use the [setType](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IValidation.html#setType) method, the [setAlertStyle](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IValidation.html#setAlertStyle) method and the [setOperator](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IValidation.html#setOperator) method of the [IValidation](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IValidation.html) interface.
*   Use [delete](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IValidation.html#delete) method of the IValidation interface to first delete validation rule and then use the [add](/document-solutions/java-excel-api/api/online/com/grapecity/documents/excel/IValidation.html#add) method to add the new rule.

Refer to the following example code to know how you can modify an existing validation rule applied to a cell or a range of cells in a worksheet.

```Java
Calendar time1 = new GregorianCalendar(1899, 11, 30, 13, 30, 0);
Calendar time2 = new GregorianCalendar(1899, 11, 30, 18, 30, 0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ss");
        
// Add Validation
worksheet.getRange("A1:A2").getValidation().add(ValidationType.Date, ValidationAlertStyle.Stop,
        ValidationOperator.Between, simpleDateFormat.format(time1.getTime()),
        simpleDateFormat.format(time2.getTime()));


// Modify validation.
worksheet.getRange("A1:A2").getValidation().setType(ValidationType.Time);
worksheet.getRange("A1:A2").getValidation().setAlertStyle(ValidationAlertStyle.Warning);
worksheet.getRange("A1:A2").getValidation().setOperator(ValidationOperator.NotBetween);
```