+ Reply to Thread
Results 1 to 16 of 16

Only Allow Paste of Values in Validation List

  1. #1
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Only Allow Paste of Values in Validation List

    I have a validated drop down list in which I'm trying to prevent pasting values over. However, I want to allow the pasting of values that are included of the drop down list.

    I've found codes that prevent pasting over validated cells, but not ones that have an exception to values within the list.

    Example:

    Suppose I have a worksheet titled Fruits with a validated drop down list in cell A1 that includes the two options "Apples" and "Bananas."

    How can I prevent another user from pasting over the cell, with the exception of "Apples" and "Bananas" (in the exact format), while also preventing paste+special of values other than "Apples" and "Bananas."

    Thank you in advance.

  2. #2
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Help with Pasting over Validated Lists

    I have a validated drop down list in which I'm trying to prevent pasting values over. However, I want to allow the pasting of values that are included of the drop down list.

    Example:

    Suppose I have a worksheet titled Fruits with a validated drop down list in cell A1 that includes the two options "Apples" and "Bananas."

    How can I prevent another user from pasting over the cell, with the exception of "Apples" and "Bananas" (in the exact format), while also preventing paste+special of values other than "Apples" and "Bananas."

    Thank you in advance.

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

    Re: Only Allow Paste of Values in Validation List

    Add this code to the worksheet's code module.
    • Right-click on the sheet tab
    • Select View Code from the pop-up context menu
    • Paste the code below in the VBA edit window
    • There are two different IF statements highlighted in the code depending on the source of your Data Validation list; a range or a comma separated list. Use one or the other.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Only Allow Paste of Values in Validation List

    Thank you for the response AlphaFrog.

    I am having trouble deciphering which part of the code to remove if my list is from a range. Would I use the code below (exactly as is) in order for it to work?

    Please Login or Register  to view this content.
    I tried using the aforementioned, but still get an error when I try to copy and paste "Apples" into the validated cell.

    Thank you in advance for the clarification.

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

    Re: Only Allow Paste of Values in Validation List

    If your list is from a range, the original code should work as it is posted. Nothing to change.

    If your list is from comma separated values, then do this:
    In the original code, comment the line
    If Evaluate...
    And uncomment this line
    If IsError...

    What is the error?
    What is the formula for the Data Validation list?
    Last edited by AlphaFrog; 06-25-2013 at 12:45 AM.

  6. #6
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Only Allow Paste of Values in Validation List

    Thanks again for the quick reply AlphaFrog

    The code I'm using is
    Please Login or Register  to view this content.
    When I copy paste (or paste special value) the exact word "Apples" over the data validated cell, the error message in the code ("Cannot paste over the data validation cell.") appears.

    The formula for the data validations is
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    ("Fruits" being the range of "Apples" and "Bananas")

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

    Re: Only Allow Paste of Values in Validation List

    Your code looks correct.
    It works for me using a named range called Fruits as the DV list range.
    I can PasteSpecial: Value and it accepts "Apples"
    If I PasteSpecial: Value it rejects "Oranges" and gives the error "Cannot paste values that are not within the list. "
    If I just paste (not PasteSpecial: Value), it gives the error "Cannot paste over the data validation cell"

    Example workbook: Special DV Lists.xlsm

  8. #8
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Only Allow Paste of Values in Validation List

    Thanks AlphaFrog. That works perfectly.

    What if I would like to use paste (not PasteSpecial: Value) for values in the DV list range also?

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

    Re: Only Allow Paste of Values in Validation List

    If you copy a cell, then using just paste will overwrite the Data Validation. I don't know how to get around that.

    If you copy just text (not a cell), then you can use just paste.

  10. #10
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Only Allow Paste of Values in Validation List

    Thanks for all the help AlphaFrog!

  11. #11
    Registered User
    Join Date
    06-14-2013
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Help with Pasting over Validated Lists

    Cell level locking1.xlsm

    Check the attachment.

    B7 cell contains on drilldown to Apple & Bananas. Once you selected anything then, B7 cell gets locked.

    To modify any data into B7 then, Press 'Unprotect Option' from Review tab and enter Password as 'abc'

    You can modify the password or data reference by pressing Alt+F11


    Regards,
    Mohan.Y

  12. #12
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,103

    Re: Only Allow Paste of Values in Validation List

    kk37,
    Please don't open duplicate posts.
    I've merged them now.
    Never use Merged Cells in Excel

  13. #13
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Help with Pasting over Validated Lists

    Hey Mohan,

    I'm trying lock a cell, without locking the worksheet, so the formula doesn't change.

    Your code
    Please Login or Register  to view this content.
    locks the value, when the cell is changed, altogether.

    For example:

    If a cell has the formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    I want it so that the user cannot change the formula, format, paste over, paste special over, etc.

    Thanks in advance.

  14. #14
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Only Allow Paste of Values in Validation List

    AlphaFrog,

    At this point, the code has the target cell referring to "A1"

    Please Login or Register  to view this content.
    Any suggestions on targeting a range, or multiple ranges (Ex. If B1:B11, B13:B15, D1:D11, and D13:D18 include DV cells).

    Furthermore, is there a way to maintain the code you provided earlier (pasting over a DV cell/cells) if a user to adds a row, or multiple rows, within the range (add 4 rows in worksheet row 2 so the range becomes B1:B15, B17:B19, D1:D15, and D17:D22).

    Thanks again in advance.
    Last edited by kk37; 06-25-2013 at 03:01 PM.

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

    Re: Only Allow Paste of Values in Validation List

    Replace this...
    If Target.Address(0, 0) = "A1" Then

    With something like this...
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Range("B1:B11,B13:B15,D1:D11,D13:D18"), Target) Is Nothing Then


    Make a Named Range of B1:B11,B13:B15,D1:D11,D13:D18 and call it say MyDVLists. Then if you insert rows within the named range e.g. at row 2, then the Named range will automatically update to include the inserted rows. Reference that Named range in the code instead of the fixed cells.
    If Target.Count > 1 Then Exit Sub
    If Not Intersect(Range("MyDVLists"), Target) Is Nothing Then

  16. #16
    Registered User
    Join Date
    06-24-2013
    Location
    Torrance, CA
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Only Allow Paste of Values in Validation List

    AlphaFrog, thanks for helping me insert rows within the data range while maintaining the code.

    If you don't mind, I have a few other questions regarding the code.

    Attached is a revised file from the original one you sent me.
    1Special DV Lists_Revised1.xlsm
    PW to sheet is: 111

    1) If I have a column of functions that is dependent to and correspond to a column of DVcells, can I duplicate the function into the inserted row when I insert a row within the range? I tried renaming the range to include the functions in column F, but it didn't work.

    Example
    Column F has the function
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    which associates to DVcells in column D. When I add a row after row 4, column B and C maintain their DV, while column F does not copy it's formula in the new row (it's blank).


    2) When I protect the worksheet, I am unable to make a selection or paste special a valid option in the DVcell. I get the error message described in the example below.

    Example
    When the sheet is protected, I try selecting "Celery" or "Spinach" in cell D1 and I get the following error within the code
    Please Login or Register  to view this content.

    3) Is it possible to lock the functions in column F, so other users cannot overwrite the function (without protecting the sheet)?


    4) Lastly, I know I asked yesterday, but maybe you have any idea on how to protect a DV cell from being pasted (not paste special) over by an invalid entry.

    Example
    If I copy and paste any value over to a DV cell (while the sheet is unprotected), you get the following error "Worksheet_Change Procedure Error - Error 1004 Application-defined or object-defined error."
    Last edited by kk37; 06-25-2013 at 06:51 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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