+ Reply to Thread
Results 1 to 10 of 10

Code for 9 conditions in a Cell

  1. #1
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    69

    Code for 9 conditions in a Cell

    Not Sure if Im in the right thread. Im looking for a code to run on a column.

    e.g
    Cells in Column D = Low, Medium, or High
    Cells in Column E = Low, Medium, or High

    Column F should have the following conditions:


    1. Green: LL(Low Probability, Low Impact), or LM (Low Probability, Medium Impact), or ML (Medium Probability, Low Impact)

    2. Yellow: LH (Low Probability, High Impact), or MM (Medium Probability, Medium Impact), or HL (High Probability, Low Impact)

    3. Red: MH (Medium Probability, or High Impact), or HM (High Probability, Medium Impact), or HH (High Probability, High Impact).


    Please help.

    Thanks

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Code for 9 conditions in a Cell

    Assuming your data is in D2 and E2 (allowing for headers), then put this in F2:

    =IF(OR(LEFT(D2)&LEFT(E2)="LL",LEFT(D2)&LEFT(E2)="ML",LEFT(D2)&LEFT(E2)="LM"),"Green",IF(OR(LEFT(D2)&LEFT(E2)="HH",LEFT(D2)&LEFT(E2)="MH",LEFT(D2)&LEFT(E2)="HM"),"Red","Yellow"))

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Code for 9 conditions in a Cell

    Sample.xlsxHello Pete,

    Thanks for the quick response., Im not sure i made everything as elaborate as possible.

    I have attached a sample document with the exact situation.


    I want column C to be automatically populated with the content it has right now if the conditions in Columns A and B are met.

    |Find the sample attached. Thank you soooo much

    Sample.xlsx
    Last edited by [email protected]; 08-05-2013 at 02:21 PM. Reason: attachment

  4. #4
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Code for 9 conditions in a Cell

    =IF(OR(AND(A2="Low",B2="Low"),AND(A2="Low",B2="Medium"),AND(A2="Medium",B2="Low")),"Green",
    IF(OR(AND(A2="Low",B2="High"),AND(A2="Medium",B2="Medium"),AND(A2="High",B2="Low")),"Yellow",
    IF(OR(AND(A2="Medium",B2="High"),AND(A2="High",B2="Medium"),AND(A2="High",B2="High")),"Red","")))
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  5. #5
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Code for 9 conditions in a Cell

    Hello Ace, Thanks for the prompt response, I tried the formula and some of the cells seem to have been missed in the calculations. They just came back as blank.

    I attach a second sample file with the solution you suggested..

    Sample2.xlsx

  6. #6
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Code for 9 conditions in a Cell

    The ones that have returned as blank have trailing spaces in the first column i.e. "High " instead of "High"

    delete those spaces and the formula will work fine

  7. #7
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,293

    Re: Code for 9 conditions in a Cell

    Remove the spaces in the cells A3, A4,....

    to late
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

  8. #8
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    69

    Thumbs up Re: Code for 9 conditions in a Cell

    GENIUS!!!! thanks fellows

  9. #9
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    69

    Re: Code for 9 conditions in a Cell

    Does anyone know how to close this thread?

  10. #10
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Code for 9 conditions in a Cell

    You said that your data was in column D and E and that you wanted the formula in column F. Change my formula to this:

    =IF(OR(LEFT(A2)&LEFT(B2)="LL",LEFT(A2)&LEFT(B2)="ML",LEFT(A2)&LEFT(B2)="LM"),"Green",IF(OR(LEFT(A2)&LEFT(B2)="HH",LEFT(A2)&LEFT(B2)="MH",LEFT(A2)&LEFT(B2)="HM"),"Red","Yellow"))

    with your data in A and B.

    To mark the thread as Solved, click on Thread Tools above your first post.

    Hope this helps.

    Pete

+ 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. VBA code brands by conditions
    By Knigtandday in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2013, 05:41 PM
  2. Meeting two conditions before proceeding with code
    By Nu2Java in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-15-2012, 10:10 AM
  3. Autofilter code, if cell Sh1 = text, then use filter on table Sh2 two conditions.
    By Justin25150 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2012, 12:52 AM
  4. Code for Multiple If conditions
    By Raushan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2007, 08:23 AM
  5. VB Code and Sum with Two Conditions
    By Gos-C in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-13-2006, 11:10 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