Modify
Modifies data validation for a range.
Syntax
expression.Modify(Type, AlertStyle, Operator, Formula1, Formula2);
expression - A variable that represents a ApiValidation class.
Parameters
| Name | Required/Optional | Data type | Default | Description |
|---|---|---|---|---|
| Type | Optional | ValidationType | The validation type. | |
| AlertStyle | Optional | ValidationAlertStyle | The validation alert style. | |
| Operator | Optional | ValidationOperator | The data validation operator. | |
| Formula1 | Optional | string | number | ApiRange | The first formula in the data validation. | |
| Formula2 | Optional | string | number | ApiRange | The second formula in the data validation. |
Returns
ApiValidation | null
Example
This example modifies a data validation rule for a range of cells.
- Code
- Result
// How to change data validation for a range of cells.
// Get a range from the worksheet and modify its data validation.
let worksheet = Api.GetActiveSheet();
worksheet.GetRange("A1").SetValue("Data Validation for decimal to be more than 10 for A2 and A5");
const range = worksheet.GetRange("A2:A5");
const targetRange = worksheet.GetRange("A4:A5");
range.SetValue("10");
const validation = range.GetValidation();
validation.Add("xlValidateDecimal", "xlValidAlertWarning", "xlGreater", "12");
targetRange.GetValidation().Modify("xlValidateDecimal", "xlValidAlertStop", "xlLess", "12");
worksheet.GetRange("A6").SetValue("Data Validation is now modified for A4:A5, to accept values less than 12.");