+ Reply to Thread
Results 1 to 6 of 6

Produce error message when pasted values break validation rules

  1. #1
    Registered User
    Join Date
    04-01-2015
    Location
    Aberdeen, UK
    MS-Off Ver
    365
    Posts
    4

    Produce error message when pasted values break validation rules

    I have a (simplified example) matrix consisting of inputs and alarms. Each action (X) should have an input and an alarm i.e. no actions should be inserted in column E or row 6.

    Capture.PNG

    I used data validation to implement this and it works.

    Capture2.PNG

    However if I paste data to these cells they do not follow the validation rules. I inserted this VBA code to prevent this (extracted from www.j-walk.com/ss/excel/tips/tip98.htm):

    Please Login or Register  to view this content.
    However, this code also prevents values from being pasted into cells even when they do not break validation rules e.g. if I paste an X to input a;alarm 1, I get an error message. Is there any way to make the make the user aware if data he/she has pasted has broken data validation rules. This can be through error/warning message or highlighting of invalid cells, whichever is possible.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Produce error message when pasted values break validation rules

    Something like this?

    Please Login or Register  to view this content.
    This assuming you have named range ValidationRange where you apply the validation range. You can change with some range address or whatever.

    In more general terms

    Please Login or Register  to view this content.
    Note that validation rule will be cleared if you paste from cell where there is no validation rule
    Last edited by buran; 04-01-2015 at 07:14 AM.
    If you are pleased with a member's answer then use the Star icon to rate it.

  3. #3
    Registered User
    Join Date
    04-01-2015
    Location
    Aberdeen, UK
    MS-Off Ver
    365
    Posts
    4

    Re: Produce error message when pasted values break validation rules

    Thanks for the reply.

    Yes I had ValidationRange set to D4:H8. In line with your comments I have altered the code to this:

    Please Login or Register  to view this content.
    This now circles all cells that have no input or alarm. But I only want cells that have an action and no input or alarm to be circled.
    To do this I know I must change the formula "=AND(NOT(ISBLANK($C4)),NOT(ISBLANK(D$3)))" but I am struggling with this. I am trying something like "=AND(ISBLANK,NOT(ISBLANK($C4)),NOT(ISBLANK(D$3)))" but this is giving an error. The answer should be pretty obvious but I can't figure it out!

  4. #4
    Registered User
    Join Date
    04-01-2015
    Location
    Aberdeen, UK
    MS-Off Ver
    365
    Posts
    4

    Re: Produce error message when pasted values break validation rules

    Okay I found the formula that works:

    "=OR(ISBLANK(D4),AND(NOT(ISBLANK($C4)),NOT(ISBLANK(D$3))))"

    now I just need a line of code that produces an error/message box notifying the user why a cell has been circled.

    e.g. If CircleInvalid=True
    MsgBox "Cell circled because..."

    Any ideas?

  5. #5
    Registered User
    Join Date
    04-01-2015
    Location
    Aberdeen, UK
    MS-Off Ver
    365
    Posts
    4

    Re: Produce error message when pasted values break validation rules

    Okay I figured it out. Code is:

    Please Login or Register  to view this content.
    Thanks for your help

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Produce error message when pasted values break validation rules

    Great! If you the problem is solved, please mark thread [SOLVED]

+ 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. Look at last pasted cell and if the same give me an error message box
    By jharaldson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2011, 08:05 PM
  2. Validation on Pasted Values
    By grey in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2009, 12:16 PM
  3. [SOLVED] cell validation even for values pasted into cells-Is there a way to validate values ?
    By JR_06062005 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

Tags for this Thread

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