Validation 对象

         
Range
Validation

代表工作表区域的数据有效性规则。

使用 Validation 对象

使用 Validation 属性可返回 Validation 对象。下面的示例改变单元格 E5 的数据有效性规则。

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

使用 Add 方法可向区域中添加数据有效性规则,并创建一个新的 Validation 对象。下面的示例给单元格 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