验证对象 (Excel)Validation object (Excel)

代表工作表区域的数据有效性规则。Represents data validation for a worksheet range.

示例Example

使用Range对象的**有效性** 属性可返回验证对象。Use the Validation property of the Range object to return the Validation object. 下例更改单元格 E5 的数据有效性规则。The following example changes the data validation for cell E5.

Range("e5").Validation _ 
 .Modify xlValidateList, xlValidAlertStop, "=$A$1:$A$10"

使用 Add 方法可将数据有效性添加到某个区域并创建一个新的 Validation 对象。Use the Add method to add data validation to a range and create a new Validation object. 此示例向单元格 E5 添加数据有效性检验。The following example adds data validation to cell E5.

With Range("e5").Validation 
 .Add Type:=xlValidateWholeNumber, _ 
 AlertStyle:=xlValidAlertInformation, _ 
 Minimum:="5", Maximum:="10" 
 .InputTitle = "Integers" 
 .ErrorTitle = "Integers" 
 .InputMessage = "Enter an integer from five to ten" 
 .ErrorMessage = "You must enter a number from five to ten" 
End With 

方法Methods

属性Properties

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.