+ Reply to Thread
Results 1 to 17 of 17

Data Validation deleted on Copy & Paste

  1. #1
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Question Data Validation deleted on Copy & Paste

    Hi there,

    I have set up data validation that works perfectly if you type in the data. The problem is the Sheet must be able to validate successfully when Copy & Paste is used as well.

    I have tried some VBA code samples on various sites, but they completely prevent data from being inserted if it does not have any validation.

    I need a way to force copied data with no validation to be pasted without deleting the existing validation rules in the cell. I cannot avoid using copy paste, so that is not an option...

    Maybe one can use code that converts any normal 'Copy & Paste' into 'Paste Special' or something like that...?

    I will greatly appreciate any help!

    Thanks

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

    Re: Data Validation deleted on Copy & Paste

    One approach is to use the Worksheet_Change event. It triggers when there is a change (e.g.; Paste) to the worksheet. You could have vba code to re-apply the DV rule to the cells you want to maintain.

    Describe what cells have data validation and what is their DV formula, or better yet, attach a desensitized example workbook.
    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
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Data Validation deleted on Copy & Paste

    Hello LeafyShroom,

    Welcome to the Forum!

    Have you considered using a Named Range for your Data Validation?

    If you don't know how to do that, then please attach a sample workbook.

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    Hi There,

    I have 2 culumns H & I. H containing a start-time value and I containing an end-time value. I have the following validation rules applied:

    Rule for H column:
    =OR(TEXT($H129,"hh-mm-ss")="NA",TEXT($H129,"hh-mm-ss")="Aborted",TEXT($H129,"hh-mm-ss")="Skipped",NOT(ISERROR(TIMEVALUE(TEXT($H129,"hh:mm:ss")))))

    Rule for I column:
    =OR(AND(OR($I129="NA",$I129="Aborted",$I129="Skipped"),$H129=$I129),AND(NOT(ISERROR(TIMEVALUE(TEXT($I129,"hh:mm:ss")))),NOT(ISERROR(TIMEVALUE(TEXT($H129,"hh:mm:ss")))),$H129<>$I129))

    The range of cells that have validation is H3 - H188 and I3 - I188

    I won't be able to write the VBA code though

  5. #5
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    Hi There,

    I have attached a simple example sheet with the same data and rules to illustrate what I mean.
    Attached Files Attached Files

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

    Re: Data Validation deleted on Copy & Paste

    This this does the validation within the code. You could remove the Data Validation from the sheet.

    To Install the code:
    • Right-click on the sheet tab
    • Select View Code from the pop-up context menu
    • Paste the code from below in the worksheet's code module


    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    Thank you, AlphaFrog, for your reply. I really appreciate it

    I have inserted the code you provided. As soon as I try and paste anything within on of the cells, I get an error saying: "Compile Error: Sub or Function not defined" and it then highlights the word/function: 'isTime'

    Do you perhaps know how I could fix that?

    Thanks!

    error.PNG
    Last edited by LeafyShroom; 02-18-2017 at 05:25 PM.

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

    Re: Data Validation deleted on Copy & Paste

    Sorry. My Bad. I forgot to give you the IsTime custom function.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    I am trying to reply, but the site is blocking my reply.

  10. #10
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    Hi AlphaFrog,

    Thank you for your reply.

    I am not getting the error anymore. I still have a problem, though.

    No matter what I type into column I it always results in an error.

  11. #11
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    I need the following to be able to happen:

    1. If text is entered, it may only be "NA" or "Skipped" or "Aborted" in either column H or I or both.
    2. If time is entered, it must be in format hhmmss and the end-time cannot be earler or equal to the start-time.
    Anything else must result in an error which should read:
    Please Insert Only: "NA" / "Skipped" / "Aborted". Make sure that the end-time is not earlier than or equal to the end-time.

    If the OK button of the message box is clicked then the edited cell must return to its original default value.

  12. #12
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Question Re: Data Validation deleted on Copy & Paste

    Hi There,

    I have tried to play around with some of the coding to try and figure something out. At this point I'm not getting any errors, but the code is not doing anything.

    I don't think I understand what I'm doing exactly (first time I ever try VBA), but I tried to use different pieces of coding from different forums to try and puzzle something together.

    Could someone please have a look and maybe modify and correct errors so it'll work if possible?

    This really is a tough one to solve...

    I'll greatly appreciate the help!
    Attached Images Attached Images

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

    Re: Data Validation deleted on Copy & Paste

    This seems to work for me.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    Hi AlphaFrog,

    Thanks for the prompt reply.

    I had a look and yes, it works, but only if I type in the values. When I Copy and Paste a time value, it still doesn't seem to work.

    Are you able to Copy and Paste and it works?

    Thanks

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

    Re: Data Validation deleted on Copy & Paste

    You're right. It doesn't trigger with paste. I'll work on it.

  16. #16
    Registered User
    Join Date
    02-15-2017
    Location
    Cape Town, South Africa
    MS-Off Ver
    Microsoft Excel 2016 MSO (16.0.7571.7095) 64-bit
    Posts
    12

    Re: Data Validation deleted on Copy & Paste

    Thanks a lot. I really appreciate the help.

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

    Re: Data Validation deleted on Copy & Paste

    Try this...
    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. Copy/Paste Overriding Data Validation
    By runnerD2016 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-11-2016, 12:01 PM
  2. Copy & paste with data validation
    By egarla in forum Excel General
    Replies: 1
    Last Post: 08-19-2014, 12:55 PM
  3. Data validation - Restrict Copy paste
    By arunrajaiah in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2014, 10:24 AM
  4. Delete user chosen row and copy and paste data from below to deleted line
    By iluvpepsico in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2014, 07:11 PM
  5. 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
  6. VBA for data validation on copy / paste
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-07-2010, 03:40 AM
  7. [SOLVED] data validation and copy/paste.......
    By MPR in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-27-2006, 10:25 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