+ Reply to Thread
Results 1 to 5 of 5

Formula that restricts a certain value in an adjacent cells based on the value written.

  1. #1
    Registered User
    Join Date
    02-14-2023
    Location
    Sydney, Australia
    MS-Off Ver
    Microsoft365
    Posts
    2

    Formula that restricts a certain value in an adjacent cells based on the value written.

    Hi,

    I'm trying to come up with a formula that will help when I'm writing a roster. I want to make sure I don't accidentally put a morning shift (i.e represented by #4) immediately after an overnight shift (represented by the number #27), cap the number of overnight shifts at no more than two in a row and make only allow an off day (represented by off). I've been trying to set it up through 'data validation', but I'd also be happy to set it up as conditional formatting so that I'm alerted to it by a colour change.

    For example

    If cell A1 = 27, A2 can only have a 27 or an OFF, it can not have a 4. Also, A3 can only have an OFF, it cannot have a 27 or a 4.


    If anyone could help I'd be very grateful! I'm starting to go cross eyed when I'm proof reading the roster.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,747

    Re: Formula that restricts a certain value in an adjacent cells based on the value written

    Welcome to the Forum HShelp!

    Please provide a complete set of rules to follow. For example, if A1=27 and A2=OFF, can A3 also be OFF?

    Also, it might be possible to do this without your file but it will go much faster if you attach a sample file so we can see where everything is, and return a file with a completed solution. See yellow banner at the to of the page.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,625

    Re: Formula that restricts a certain value in an adjacent cells based on the value written

    If data is starting from Row refer to Sheet1.
    Select A1:A10. Formula for DV
    Please Login or Register  to view this content.
    If Data is starting after 2nd row refer Sheet2.
    Select A3:A13. Formula for DV
    Please Login or Register  to view this content.
    In this case Ignore Blank should be unchecked.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  4. #4
    Registered User
    Join Date
    02-14-2023
    Location
    Sydney, Australia
    MS-Off Ver
    Microsoft365
    Posts
    2

    Re: Formula that restricts a certain value in an adjacent cells based on the value written

    Thanks for your interest Jeff and kvsrinivasamurthy
    I’ve attached an example of the roster that I’d be hoping to apply the formula to. There’d be a range of different values including cells that would contain text and numbers. I stuffed up in the original post. The roster is horizontal, not vertical, so the example should be if:

    C3 = 27, D3 = OFF or 27
    If C3 & D3 = 27, E3 = OFF
    If C3=27, D3=OFF, E3 can = OFF, 1, 4 or 7

    I hope this makes sense!
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,647

    Re: Formula that restricts a certain value in an adjacent cells based on the value written

    This proposal employs two conditional formatting rules
    1. applied to the range D3:AR16: =AND(C3=27,D3<>27,D3<>"off")
    2. applied to the range E3:AR16: =AND(C3=27,D3=27,E3<>"off")
    Both rules produce red fill.
    Let us know if you have any questions.
    Attached Files Attached Files
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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. [SOLVED] Apply formula based on the equality of adjacent cells
    By hasan mougharbel in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-21-2022, 07:59 AM
  2. [SOLVED] mark color for not matched items for adjacent cells based on another adjacent cells
    By tubrak in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-14-2022, 08:02 AM
  3. Data Validation Restricts a Cell Based on Value Entered
    By STBTC in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-10-2017, 03:00 AM
  4. Replies: 3
    Last Post: 06-15-2017, 05:42 PM
  5. Macro to populate cells with formula based on adjacent cell
    By eoghanmolloy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2014, 07:06 AM
  6. Replies: 4
    Last Post: 09-16-2011, 09:28 AM
  7. Formula based on contents of adjacent cells?
    By Finalfrontier1976 in forum Excel General
    Replies: 2
    Last Post: 05-07-2010, 07:38 PM

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