Expand Minimize

NamedRange.Validation Property

Gets a Validation object that represents data validation for the NamedRange control.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Validation Validation { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Validation
A Validation object that represents data validation for the NamedRange control.

You must use the Startup event handler of a worksheet to add validation to a named range. For more information about the Startup event handler, see Events in Office Projects.

The following code example uses the Validation property to verify that a string with at least three characters is entered into a NamedRange. The SetValidation method must be called from the Startup event handler.

This example is for a document-level customization.


private void SetValidation()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", missing],
        "namedRange1");

    namedRange1.Validation.Add(
        Excel.XlDVType.xlValidateTextLength,
        Excel.XlDVAlertStyle.xlValidAlertStop,
        Excel.XlFormatConditionOperator.xlGreater, 3, missing);

    namedRange1.Validation.InputMessage = "Enter a name.";
    namedRange1.Validation.ErrorMessage =
        "Please enter a name with 3 or more characters.";
}


Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft