Check To See If A Cell Have Data Validation

markkramer

Board Regular
Joined
May 8, 2002
Messages
162
Hi!

Is there an expression that can be used to check to see if a cell has data validation associated with it? In psuedo-code, I'm looking to do this:

If Range("A1").Validation = False
msgbox("Hey! You got rid of the data validation!")
Endif
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Tom Urtis

MrExcel MVP
Joined
Feb 10, 2002
Messages
11,274
Sub Test1()
On Error Resume Next
If ActiveCell.Validation.Type <> 0 Then
If Err.Number <> 0 Then
Err.Clear
MsgBox _
"Cell " & ActiveCell.Address(0, 0) & _
" does not have data validation.", _
48, "No DV here"
Else
MsgBox _
"Cell " & ActiveCell.Address(0, 0) & _
" has data validation.", _
64, "Seek and you shall find."
End If
End If
End Sub
 

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myCol%
Dim myRow&

If Selection.Count > 1 Then Exit Sub

myCol = Target.Column
myRow = Target.Row

On Error GoTo myErr
If Not IsMissing(Cells(myRow, myCol).Validation.Operator) Then _
MsgBox "This cell has Data Validation!", vbInformation + vbOKOnly, "Data Validation!"
Exit Sub

myErr:

MsgBox "Hey! You got rid of the data validation!", vbExclamation + vbOKOnly, "Validation Error!"
End Sub
 

Forum statistics

Threads
1,176,387
Messages
5,902,789
Members
434,996
Latest member
aimeea

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top