+ Reply to Thread
Results 1 to 2 of 2

Copy/Paste form another excel workbook overrides data validation.

  1. #1
    Registered User
    Join Date
    10-07-2014
    Location
    Delhi
    MS-Off Ver
    2007
    Posts
    1

    Copy/Paste form another excel workbook overrides data validation.

    I have viewed similar posts on the internet but none have worked for me
    I have an excel sheet with data validation applied to multiple columns. Data validation prevents from entering an incorrect value when typed into the cells but when I copy any other value from another excel workbook and paste it in the cells, it overrides the data validation. I have found the below code but it only applies when I copy and paste data from the same excel sheet. Can someone please help me with the code for applying data validation to multiple columns upon copy paste from another excel workbook. Thanks.

    Private Sub Worksheet_Change(ByVal Target As Range)
    'Does the validation range still have validation?
    If HasValidation(Range("ValidationRange")) Then
    Exit Sub
    Else
    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

  2. #2
    Valued Forum Contributor Naveed Raza's Avatar
    Join Date
    11-04-2012
    Location
    India, Hyderabad
    MS-Off Ver
    Excel, Access 2007/2010
    Posts
    1,338

    Re: Copy/Paste form another excel workbook overrides data validation.

    Assalamualaikum , Eid - Mubarak...!

    please use Code tags while posting code

    first add code tags and then please provide sample workbook files
    Thanks - Naveed
    -----------------------------
    If the suggestion helps you, then Click * to Add Reputation
    To Attach File: Go Advanced>>Manage Attachments>>Add Files (In Top Right Corner)>>SelectFiles>>.........Locate Your File(s)>>Upload Files>>Done (In Bottom Right)
    1. Use [code] code tags [\code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    2. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel VBA filter to criteria and copy data and paste to another workbook
    By aalvaro03 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2013, 07:33 PM
  2. Copy data against each checked check box and paste in a new excel workbook
    By rnd in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-28-2010, 06:04 AM
  3. validation rules not working when someone copy paste data on validation cell
    By jthakrar in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-17-2010, 03:36 AM
  4. Prevent Copy/paste ruining data validation in shared workbook
    By owlie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2009, 12:28 AM
  5. Data from Input Box overrides cell input validation
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-01-2007, 02:29 PM

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