How To Check Cell Is Having Validation Or Not Using VBA in Microsoft Excel 2010

In this article, you will learn how to check if the cells contain data validation or not using VBA code.We will use VBA code to create UDF function to return TRUE or FALSE.

You can control the type of data or the values that users enter into a cell through data validation. Data validation helps the owner of the Excel book to restrict data entry to a certain data type.
 
Click on Developer tab

From Code group, select Visual Basic
 
img1
 
Click on Insert, and then Module
 
img2
 
This will create new module.

Enter the following code in the Module
 
Function ISDatavalidation(rng As Range) As Boolean

    On Error Resume Next

DVtype = rng.Validation.Type

    On Error GoTo 0

 

    If DVtype = 3 Then

ISDatavalidation = True

    Else

ISDatavalidation = False

    End If

End Function
 
img3
 
The new UDF formula is created with name ISDatavalidation

There is only one parameter; the lookup cell that needs to be checked whether it contains data validation or not.

Following is the snapshot of the data where column A contains Month through data validation
 
img4
 
In cell B1, the formula would be =ISdatavalidation(A1)& then copy down the formula, and we will get the output.
 
img5
 
In this way, you can find out whether the cells contain data validation or not.
 
 

Leave a Reply

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

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.