Reliable Data Validation

Written by Allen Wyatt (last updated February 14, 2026)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365


1

Tomek has two cells, B3 and B4, both of which have data validation applied to them. In cell B3, data validation requires a whole number between 1 and 5. In cell B4, data validation requires a whole number between 6 and 10. If Tomek selects the range B3:B4, types 3, and presses Ctrl+Enter, then both cells end up with 3 in them. This, despite the data validation rule in cell B4. Excel only pays attention to the data validation rule, if any, in the first cell in the selected range. Tomek wonders if there is a way to enforce data validation on individual cells in a selection so this doesn't happen.

The short answer is that there are several loopholes (for lack of a better term) where data validation doesn't work. Tomek has identified one such loophole—the entry of values into a range of cells using Ctrl+Enter. Since that is the specific condition about which Tomek is asking, there is a relatively easy macro-based approach that can be employed. The following macro can be added to the worksheet's code:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim c As Range

    Application.EnableEvents = False
    For Each c In Target
        If Not c.Validation Is Nothing Then
            On Error Resume Next
            If c.Validation.Type <> 0 Then
                If Not c.Validation.Value Then
                    MsgBox "Invalid entry in cell " & _
                      c.Address(False, False), vbExclamation
                    c.ClearContents
                End If
            End If
            On Error GoTo 0
        End If
    Next c
    Application.EnableEvents = True
End Sub

Every time a change is made in the worksheet, the macro runs, checking each cell that is selected. If the cell has a data validation rule set, then it is checked. If the rule fails, then the user is notified and the next cell is checked.

Notice that the macro will work with any changes done in the worksheet; it doesn't matter where they are done. It is possible to modify the macro to only check if the change was in the range B3:B4, but I suspect that the example range was just for example, not for limitation of where edits are expected.

There are three obvious drawbacks to using an approach such as this. The first has already been implied: The macro doesn't deal with all potential data validation loopholes, such as pasting a value to overwrite data validation rules. The second drawback is that using the user won't be able to use Ctrl+Z to undo edits. And, of course, the third drawback is that the workbook must be macro enabled.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12240) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Excel Information to a Web Page

Besides saving a worksheet as a complete Web page, you can also save smaller portions of your data to an existing Web ...

Discover More

Changing Font Color

There are any number of reasons to format different cells in different colors. Excel allows you to easily change the ...

Discover More

Counting Words the Old Fashioned Way

One way to specify word count is to count characters and divide by five. If you still need this old-fashioned way of ...

Discover More

Dive Deep into Macros! Make Excel do things you thought were impossible, discover techniques you won't find anywhere else, and create powerful automated reports. Bill Jelen and Tracy Syrstad help you instantly visualize information to make it actionable. You’ll find step-by-step instructions, real-world case studies, and 50 workbooks packed with examples and solutions. Check out Microsoft Excel 2019 VBA and Macros today!

More ExcelTips (ribbon)

Prohibiting Single-Digit Entries in a Cell

The Data Validation capabilities of Excel can be very helpful when you are trying to control what people can enter into a ...

Discover More

Adding Pop-Up Documentation to a Cell

Want to have a small help screen pop up when a user selects a particular cell? This can be done by using data validation, ...

Discover More

Complex Data Input Limitations

Data Validation is a great tool in Excel for making sure that whatever is entered in a cell matches your specific ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five more than 5?

2026-02-14 20:44:30

Tomek

Thank you, Allen, for replying to my request.
The macro you proposed works well and does exactly what I wanted. Moreover, the first loophole you mentioned (pasting values into validated cells) is actually handled correctly. This is important for me as I often paste the data from another workbook, which is extracting the game score results from social media, where participants share them with the group. If I mis-align the pasted data, they will almost certainly break validation rules, and your macro will let me know.
It even works when the cell's or cells' value is changed by a macro, which standard validation does not check.

You are correct that I have large areas of validated data, not just two cells, but modifying the macro to check all the validated cells when only a few cells were changed would be inefficient. However, I can easily modify your macro to check all validated cells and run it on demand, say before archiving a full month of data.

Thanks again.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.