+ Reply to Thread
Results 1 to 18 of 18

Protect data validation list from copy paste

  1. #1
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Protect data validation list from copy paste

    Hi all!

    I have a file to be filled by several users. In some columns I have put data validation lists so as the users to use specific values. The problem is that if a user copy and paste something the data validation list disappears. If you write on the cell you get the error message but in copy/paste you are not... Copy/Paste should not be allowed. In the protection menu there is no option for data validation cells.

    Has anyone found a solution to this problem? I searched some threads but I didn t find anything. I guess this is a known problem.

    Any help will be appreciated

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Protect data validation list from copy paste

    I found this clever solution.
    Prevent Copy/Paste over Data Validated cells
    Scroll down to the middle of the link labeled Prevent Copy/Paste over Data Validated cells.

    ...write a macro that detects updates to the cells, determines if data validation is enabled on the cells, and then denies the paste if true.
    1. Select all the cells that have data validation and name them DataValidationRange. You can name ranges of cells by typing the name to the left of the formula bar, where the Cell address is located.
    2. In the code module for the worksheet (Sheet1, for example), add the following code:

    Please Login or Register  to view this content.
    Unfortunately, VBA is the only way to prevent someone from pasting over the cells. This has been an issue with Data Validation in Excel since the beginning. Hope it helps either way.
    Last edited by AlphaFrog; 02-24-2016 at 06:11 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    Hi Alpha Frog,

    Thanks for the answer,

    I tried it but it didn t work.
    I selected all the cells with data validation list (in several columns), I named them as mentioned and copied/pasted the code. I saved the file as xlsm and I tried a paste in a cell. I got the following error:

    Run-time error '28':
    Out of stack space

    Continue - End - Debug - Help

    I pressed Debug and the "Application.Undo" part of the code turned yellow...

    What is that???

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Protect data validation list from copy paste

    Application.Undo undoes the last action (paste). It's just like clicking the undo icon.

    I don't know why it's throwing an error there.

  5. #5
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    I named 5000 cells per column (*10 columns) with data validation list in them. Is it possible the error correlates with the number of cells?

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Protect data validation list from copy paste

    Quote Originally Posted by Eftychia View Post
    I named 5000 cells per column (*10 columns) with data validation list in them. Is it possible the error correlates with the number of cells?
    Unless you're pasting over all 5000 cells, I wouldn't think that would be an issue. As a test, try it on a sheet with just a few DV cells.

  7. #7
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    I just created a file with some data validated cells and it worked. In the data validation though, didn t let me use as source a list in another worksheet (excel 2007). The list had to be in the same sheet with the data validated cell. The file I used it at work has the lists in another sheet (excel 2010). Do you think that s the problem? I am going to put the lists in the same sheet and see what happens...

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Protect data validation list from copy paste

    You can use list validation where the list is on another sheet, but you need to create a named range (static or dynamic), and use that instead of referring to the range directly.

    For example, to use the validation range Sheet2!A1:A10 on Sheet1, create a name with either Workbook or Sheet1 scope that refers to it (Bob Refers to: Sheet2!A1:A10), and then use that name in the DV: =Bob

    Also, the code should bracket the Undo statement with Application.EnableEvents = False/True to avoid retriggering itself.
    Entia non sunt multiplicanda sine necessitate

  9. #9
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    thanks shg,

    I did the named range and the data validation worked with the list in another sheet.

    What do you mean with "Also, the code should bracket the Undo statement with Application.EnableEvents = False/True to avoid retriggering itself."? Should I change something in the code?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Protect data validation list from copy paste

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    Thanks,

    I will try it tomorrow at work and let you know
    Hope it works

  12. #12
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    Hi again,

    If I replace the "Application.Undo" with the :

    Please Login or Register  to view this content.
    then the message box appears even if I choose something on the list and not only in copy/paste.

    I tried the code:

    Please Login or Register  to view this content.
    in a xlsm with 3 columns of data validation and it didn t work. I attach a file to see the exact error message. Just choose in a blue cell a value from the list.
    Warning! Better save any open workbook before because the programm stucks...
    Attached Files Attached Files
    Last edited by Eftychia; 02-28-2016 at 04:24 PM.

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Protect data validation list from copy paste

    Please take a few minutes to re-read the forum rules, and then edit your post to add CODE tags.

    Thanks.

  14. #14
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    sorry shg,

    I added code tags

  15. #15
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Protect data validation list from copy paste

    Thank you.

    Untested:

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    Still an error,

    Run time error '13'
    Type mismatch
    Please Login or Register  to view this content.

    I attach the file with the code.
    What this error means?
    Attached Files Attached Files

  17. #17
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Protect data validation list from copy paste

    Sorry:

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    03-13-2014
    Location
    Athens, Greece
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Protect data validation list from copy paste

    corrected,

    now the message box appears not only when I copy/paste a cell but also when I select a value from the list.

    I attach again the file.

    Do you think that maybe we shouldn t use the DataValidationRange in a 3 column-range but use different names for each column? And use something like AND fuction in the code?
    Attached Files Attached Files

+ 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. VBA to Copy & Paste Data dependant on selection in a Data Validation List
    By Clinno in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-30-2015, 10:10 PM
  2. Copy validation list and paste it as values
    By srevanth in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-06-2014, 12:13 PM
  3. [SOLVED] change validation list value and copy and paste from dependent cells
    By j.farr3ll in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-13-2014, 06:30 AM
  4. Validation List to copy and paste in specific area (excel 2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2012, 02:22 PM
  5. [SOLVED] Protect Data Validation cells from Copy Paste
    By amotto11 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-09-2012, 05:06 PM
  6. 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
  7. How to paste into a Data validation list?
    By evillen2 in forum Excel General
    Replies: 3
    Last Post: 04-05-2007, 11:36 AM

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