ExcelScript.DataValidationErrorAlert interface

Represents the error alert properties for the data validation.

Remarks

Examples

/**
 * This script creates a data validation rule for the range B1:B5.
 * All values in that range must be a positive number.
 * Attempts to enter other values are blocked and an error message appears.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the range B1:B5 in the active worksheet.
  const currentSheet = workbook.getActiveWorksheet();
  const positiveNumberOnlyCells = currentSheet.getRange("B1:B5");

  // Create a data validation rule to only allow positive numbers.
  const positiveNumberValidation: ExcelScript.BasicDataValidation = {
    formula1: "0",
    operator: ExcelScript.DataValidationOperator.greaterThan
  };
  const positiveNumberOnlyRule: ExcelScript.DataValidationRule = {
    wholeNumber: positiveNumberValidation
  };

  // Set the rule on the range.
  const rangeDataValidation = positiveNumberOnlyCells.getDataValidation();
  rangeDataValidation.setRule(positiveNumberOnlyRule);

  // Create an alert to appear when data other than positive numbers are entered.
  const positiveNumberOnlyAlert: ExcelScript.DataValidationErrorAlert = {
    message: "Positive numbers only",
    showAlert: true,
    style: ExcelScript.DataValidationAlertStyle.stop,
    title: "Invalid data"
  };
  rangeDataValidation.setErrorAlert(positiveNumberOnlyAlert);
}

Properties

message

Represents the error alert message.

showAlert

Specifies whether to show an error alert dialog when a user enters invalid data. The default is true.

style

The data validation alert type, please see ExcelScript.DataValidationAlertStyle for details.

title

Represents the error alert dialog title.

Property Details

message

Represents the error alert message.

message: string;

Property Value

string

showAlert

Specifies whether to show an error alert dialog when a user enters invalid data. The default is true.

showAlert: boolean;

Property Value

boolean

style

The data validation alert type, please see ExcelScript.DataValidationAlertStyle for details.

style: DataValidationAlertStyle;

Property Value

title

Represents the error alert dialog title.

title: string;

Property Value

string