+ Reply to Thread
Results 1 to 7 of 7

Clear contents of cell if unallowed data entered

  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    Miami, FL
    MS-Off Ver
    Excel 2010
    Posts
    3

    Clear contents of cell if unallowed data entered

    Hello,

    In my column J, the only value that is allowed to be entered is "AR". If they enter anything other than "AR", I want a message to pop up that says something like "This condition is not allowed....etc " and I also want the data that was entered for that cell only to be cleared.

    So far I am able to bring up the message but don't know how to clear the contects. See below.

    Your help is greatly appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Clear contents of cell if unallowed data entered

    Hi, tysonz1987,

    maybe like this:

    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Clear contents of cell if unallowed data entered

    a mon-VBA option would be to put AR in a cell somewhere, and then use Data Validation to restrict entry to just what that cell contains. you can make the "message" anything you want
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Clear contents of cell if unallowed data entered

    Try this -
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Registered User
    Join Date
    09-27-2012
    Location
    Miami, FL
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Clear contents of cell if unallowed data entered

    thank you all for your help.

    HaHoBe - your code worked well and I am going to go with yours.

    arlu1201 - for some reason adding the "target.clearContents" caused some sort of looping (the message box would repeatedly pop up after pressing ok) and then it would crash the program.

    FDibbins - thank you for your advice

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Clear contents of cell if unallowed data entered

    Based on your last post in this thread, its apparent that you are satisfied with the solution(s) you've received and have solved your question, but you haven't marked your thread as "SOLVED". I will do it for you this time.

    In future, to mark your thread as Solved, you can do the following -
    Select Thread Tools-> Mark thread as Solved.

    Incase your issue is not solved, you can undo it as follows -
    Select Thread Tools-> Mark thread as Unsolved.

    Also, since you are relatively new to the forum, i would like to inform you that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post which helped you. This adds to the reputation of the person who has taken the time to help you.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Clear contents of cell if unallowed data entered

    thanks for the star

+ 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