Results 1 to 6 of 6

Produce error message when pasted values break validation rules

Threaded View

oliveirano25 Produce error message when... 04-01-2015, 06:45 AM
buran Re: Produce error message... 04-01-2015, 07:10 AM
oliveirano25 Re: Produce error message... 04-01-2015, 08:54 AM
oliveirano25 Re: Produce error message... 04-01-2015, 09:23 AM
oliveirano25 Re: Produce error message... 04-01-2015, 09:10 AM
buran Re: Produce error message... 04-01-2015, 10:18 AM
  1. #1
    Registered User
    Join Date
    04-01-2015
    Location
    Aberdeen, UK
    MS-Off Ver
    365
    Posts
    4

    Produce error message when pasted values break validation rules

    I have a (simplified example) matrix consisting of inputs and alarms. Each action (X) should have an input and an alarm i.e. no actions should be inserted in column E or row 6.

    Capture.PNG

    I used data validation to implement this and it works.

    Capture2.PNG

    However if I paste data to these cells they do not follow the validation rules. I inserted this VBA code to prevent this (extracted from www.j-walk.com/ss/excel/tips/tip98.htm):

    Private Sub Worksheet_Change(ByVal Target As Range)
        'Does the validation range still have validation?
        If HasValidation(Range("ValidationRange")) Then
            Exit Sub
        Else
           Application.EnableEvents = False
           Application.Undo
            MsgBox "Your last operation was canceled." & _
            " It would have deleted data validation rules.", vbCritical
        End If
    End Sub
    
    Private Function HasValidation(r) As Boolean
    '   Returns True if every cell in Range r uses Data Validation
        On Error Resume Next
        x = r.Validation.Type
        If Err.Number = 0 Then HasValidation = True Else HasValidation = False
    End Function
    However, this code also prevents values from being pasted into cells even when they do not break validation rules e.g. if I paste an X to input a;alarm 1, I get an error message. Is there any way to make the make the user aware if data he/she has pasted has broken data validation rules. This can be through error/warning message or highlighting of invalid cells, whichever is possible.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Look at last pasted cell and if the same give me an error message box
    By jharaldson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2011, 08:05 PM
  2. Validation on Pasted Values
    By grey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2009, 12:16 PM
  3. [SOLVED] cell validation even for values pasted into cells-Is there a way to validate values ?
    By JR_06062005 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1