• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Prevent paste in data validation list

rasull13

New Member
hi. i need a vba code to prevent users from paste in to cell that have data validation list. i have this code. but this code not allow to select item from list or not allow to write in




Code:
If HasValidation(Range("y19:bc48")) Then
      Application.EnableEvents = True
     
     
        Exit Sub
    Else
        Application.Undo
        MsgBox "Error: You cannot paste data into these cells." & _
        "Please use the drop-down to enter data instead.", vbCritical
    End If



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
--------------------------------------------------------------------------------------------
Mod Edit: Added code tag.
 
Last edited by a moderator:
Back
Top