+ Reply to Thread
Results 1 to 7 of 7

Prevent data entry in cell A1 if there is data in a cell B1 and vice versa

  1. #1
    Registered User
    Join Date
    02-28-2008
    Posts
    36

    Prevent data entry in cell A1 if there is data in a cell B1 and vice versa

    I need to prevent the user from entering data in cells A1 & B1 on the same row. They need to use one or the other. For instance on row 1 they may need to use A1 therefore they cannot use B1, then on row 2 they may need to use B2 therefore they cannot use A2. If they use both cells on the same row the formulas dont work properly in other cells dependent on these cells. I need it to work like this all the way down the spreadsheet.

    Thanks for the help

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    One way would be the following worksheet Selection_change event macro. It puts a null value in an A or B cell of the B or A adjacent cell has a value. If you want a zero value rather than null just change the
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-28-2008
    Posts
    36
    Thanks for the response, but that only kind of works. I dont know if it has anything to do with it but I have a valildation list in those to cells. If I select data in the A cell, it will still allow me to select data from the list in the B cell, and then which ever cell A or B I click on next it will remove the data from that cell. If I dont click on either cell it will keep data in both cells.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Maybe like this:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-28-2008
    Posts
    36
    Thankyou that works great

  6. #6
    Registered User
    Join Date
    02-28-2008
    Posts
    36
    This code works fine on the sheet until I try to add a page. When I say "add a page" I mean there is a macro that adds an additional page to this sheet, when the user runs out of lines, they click and add page button and it adds another page to the sheet.
    When you try to add a page it gives a:

    "Runtime Error"
    "Application-defined or object defined error"

    Then if you debug it it takes you to this code and highlights in yellow the line
    .Offset(, IIf(.Column = 1, 1, -1)).ClearContents


    Please Login or Register  to view this content.
    Im an amatuer at best, when it comes to VBA code sometimes I can understand and work my way through some of this stuff, but this line has me baffled.

    I would like to attach the file but even zipped it is to large to attach.
    Thanks for all the help

  7. #7
    Registered User
    Join Date
    02-28-2008
    Posts
    36
    any ideas
    thanks

+ 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