Skip to main content

Validation object

Table of contents
  1. Example

Represents data validation for a worksheet range.


Use the Validation property of the Range object to return the Validation object. The following example changes the data validation for cell E5.

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

Use the Add method to add data validation to a range and create a new Validation object. 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

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>