+ Reply to Thread
Results 1 to 9 of 9

Validate if cell already has a value in it

  1. #1
    Registered User
    Join Date
    11-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2002
    Posts
    10

    Validate if cell already has a value in it

    I need some vba which checks if a user has already entered data into a cell. Basically, imagine 4 non-adjacent cells (eg. A5, A12, A16, A20). If the user adds data to A5 and then tries to add data to A12 (or A16 or A20) I need to stop this. The user can only add data to one of the four cells. Thanks for any help.

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Validate if cell already has a value in it

    hi mickwooduclan, welcome to the forum. here'a non-VBA way of doing it. press the CTRL key & click on the 4 cells. not sure if Excel 2002 has the same shortcut. press ALT + D + L to go to the Data Validation Window. put a custom formula like this:
    =COUNTA($A$5,$A$12,$A$16,$A$20)<=1

    you can also put an error message like i have. please see attached. i remember answering a similar question & a user Jakobshavn had a VBA solution to it. unable to find the thread though.
    Attached Files Attached Files

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  3. #3
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Validate if cell already has a value in it

    Hello Mick
    With acknowledgement to benishiro here is a bare-bones VBA option to consider

    Please Login or Register  to view this content.
    barry
    If this was helpful then please click the small star icon at the bottom left of my post. A little appreciation goes a long way.

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Validate if cell already has a value in it

    Adding to barry's solution. You'll need to select another cell otherwise user will still be able to enter data into the cell. See code highlighted in red.

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Validate if cell already has a value in it

    You could use the custom validation formula =(COUNTA($A$5, $A$12, $A$16, $A$20)<=1) in all four of the cells.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    11-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2002
    Posts
    10

    Re: Validate if cell already has a value in it

    Many thanks everyone - lots of solutions - I like the custom validation formula but I'll check them all.

  7. #7
    Registered User
    Join Date
    11-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2002
    Posts
    10

    Re: Validate if cell already has a value in it

    I've just realised that I need to have two validations in the same cell. The first validation checks whether the user has input between (eg) 25.4 and 30 (I'm using allow decimals between two values). The second validation is the original subject of this thread - eg. =(COUNTA($A$5, $A$12, $A$16, $A$20)<=1). So, can I concatenate two lots of data validation somehow?

  8. #8
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Validate if cell already has a value in it

    change it to this:
    =AND(COUNTA($A$5,$A$12,$A$16,$A$20)<=1,SUM($A$5,$A$12,$A$16,$A$20)>=25.4,SUM($A$5,$A$12,$A$16,$A$20)<=30)

  9. #9
    Registered User
    Join Date
    11-11-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2002
    Posts
    10

    Re: Validate if cell already has a value in it

    Not quite - each of the 4 cells will validate against different numbers - In A5 between 25.4 and 30, in A12 between 18.4 and 25.3 and so on. If someone score 27.2 (in A5) they can't also score 23.7 in A12. Hope that makes sense. Thank you again for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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