Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 35 of 35

Thread: Solved: IF(AND(OR Formula Help Take 2!

  1. #21
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Ok Bob i'll make it as english as i can but it's quite a mess in my head at times!

    Selections Available:
    LCO, Line Check, Line Clean, Line Off, Line On, No Ops, Re-pack, Ln Maintainance


    The Formula Cell result shoud be value of B31 if:
    C2= "No Ops" G2="No Ops"
    C2= "Line Off" G2="Line Off"
    C2= "No Ops" G2="Line Off"......this is the criteria that causes FALSE
    C2= "Line Off" G2="No Ops".......this is the criteria that causes FALSE
    And D4=""

    The Formula Cell result shoud be "" if:
    C2= "Line On" G2= ANY OTHER SELECTION
    C2= ANY OTHER SELECTION G2="Line On"
    And D4=""

    The Formula Cell result shoud be "" if:
    C2= ANY SELECTION
    G2= ANY SELECTION
    And D4 ="" (except first set of results i.e Line off Line off etc)

    The Formula Cell result shoud be "" if:
    C2= ANY SELECTION
    G2= ANY SELECTION
    And D4 <>""

    =IF(AND(D4<>""),IF(OR(C2="No Ops",C2="Line Off",C2="Line Clean",C2="LCO",C2="Ln Maintainance",C2="Re-Pack",C2="Line Check",C2="Line On",G2="No Ops",G2="Line Off",G2="Line Clean",G2="LCO",G2="Ln Maintainance",G2="Re-Pack",G2="Line Check",G2="Line On"),"",""),IF(OR(C2="Line On",G2="Line On"),"",IF(AND(C2="No Ops",G2="No Ops"),IF(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",B31),IF(AND(C2="Line Off",G2="Line Off"),IF(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",B31)))))
    this works fine except for the criteria pointed out in the first results criteria!

    Hope this helps,

    Regards,
    Simon

    P.S Thanks for your patience Bob
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  2. #22
    VBAX Regular Gert Jan's Avatar
    Joined
    Oct 2006
    Location
    Houten
    Posts
    62
    Location
    Just to make sure, does this do the first part?

    The Formula Cell result shoud be value of B31 if:
    C2= "No Ops" G2="No Ops"
    C2= "Line Off" G2="Line Off"
    C2= "No Ops" G2="Line Off"......this is the criteria that causes FALSE
    C2= "Line Off" G2="No Ops".......this is the criteria that causes FALSE
    And D4=""

    =IF(AND(D4="",OR(AND(C2="No Ops",G2="No Ops"),AND(C2="Line Off",G2="Line Off"),
    AND(C2="No Ops",G2="Line Off"),AND(C2="Line Off",G2="No Ops"))),B31,"")

  3. #23
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I may be over-simplifying it, but it just looks like this to me

    =IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),B31,"")

  4. #24
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Gert that is correct!

    Bob - With your usual clarity hit the nail on the head for the first part!, I cant believe i went so complicated!

    Now i need to incorporate the next criteria - so with the combination you put together in your last post if these cells have these values
    J5=2,L5=2,N5=2,R5=2,T5=2,V5=2
    and D4="" then cell should display blank - this is because the Ops will be used at another line.

    I did try combinations of this
    =IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),B31,"",if(and(D4="",if(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",B31)) )
    but either got the message "Too Many Arguments" Or " You Have Typed An Error" or i could get it to leave the contents of B31 in the cell regardless of any other criteria.

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #25
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Bob - All,

    I have managed to get the two formulae together and it works perfect, Bob thanks for your time and trouble last night on this!

    Final Formula:
    =IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),IF(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",B31)),IF(AND(OR(C2={"Line On","Line On"})),"",""))
    Thanks again to all.

    regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #26
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    Bob - With your usual clarity hit the nail on the head for the first part!, I cant believe i went so complicated!
    Simon, I think that the problem is that you try and construct a formula that meets the first condition, then add on the next, then the next, and so on.

    By writing it down as you did, you can see the pattersn, and construct an OVERALL solution. Like all things, formulae benefit from a bit of thought and design (45 minutes into the formulae course <G>).

    Quote Originally Posted by Simon Lloyd
    Now i need to incorporate the next criteria - so with the combination you put together in your last post if these cells have these values and D4="" then cell should display blank - this is because the Ops will be used at another line.
    First, let's construct an English view as before

    D4=""
    C2= "No Ops" G2="No Ops"
    C2= "Line Off" G2="Line Off"
    C2= "No Ops" G2="Line Off"......this is the criteria that causes FALSE
    C2= "Line Off" G2="No Ops".......this is the criteria that causes FALSE
    >>> Result: B31

    C2= "Line On" G2= ANY OTHER SELECTION
    C2= ANY OTHER SELECTION G2="Line On"
    >>> Result: ""

    C2= ANY SELECTION
    G2= ANY SELECTION
    >>> Result: ""

    J5= 2 OR L5=2 OR N5=2 OR R5=2 OR T5=2 OR V5=2
    C2= ANY SELECTION (inc. the first test values)
    G2= ANY SELECTION (inc. the first test values)
    >>> Result: ""

    D4 <>""
    C2= ANY SELECTION
    G2= ANY SELECTION
    >>> Result: ""

    Assuming that I have correctly interpreted the criteria, the first thing that hits me is the

    C2= ANY SELECTION (inc. the first test values)

    in the new test, which suggests that we cannot add a simple extra IF after the other tests, as the previous criteria will have already set the result, so we need to do it first. All we need is to add

    IF(AND(D4="",OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2)),"",

    to the formula, giving

    =IF(AND(D4="",OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2)),"",
    IF(AND(D4="",OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"})),B31,""))
    One thing to notice is that both of the first two tests check for D4="", so we could abstract this

    =IF(D4="",
        IF(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",
        IF(AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"})),B31,
      "")))
    Quote Originally Posted by Simon Lloyd
    I did try combinations of this
    =IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),B31,"",if(and(D4="",if(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",B31)) )
    but either got the message "Too Many Arguments" Or " You Have Typed An Error" or i could get it to leave the contents of B31 in the cell regardless of any other criteria.
    The problem here is that you tried to add a condition after the formula was complete, that is the first condition had a TRUE action (B31) and a FALSE action (""), so you cannot just tag another test after that, you have to replace the FALSE action.

    Doing that still gives an error, as you have used AND(D4="" and then added IF which is redundant, you should use

    IF(AND(D4="",OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2)),

    which gives a final formula of

    =IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),B31,
      IF(AND(D4="",OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2)),"",B31))
    but as I said earlier, this doesn't fail but it doesn't work because that final condition never gets tested, the other conditions would return a result previously.

  7. #27
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Thanks for the lesson Bob,
    formulae benefit from a bit of thought and design (45 minutes into the formulae course <G>).
    Wow!, i'd be galloping to the last fence by then with half a horse!!!! but you should know me by know - fingers start working a couple of hours before the brain does! Lol.

    I did kind of figure out that in order to "Tag" another formula on the end i had to break the end of the formula - so in actual fact i was using my next statement as the True part of the last statement _ but as you pointed out i would still run in to difficulty!

    My last formula posted seems to work in every respect, have i stumbled on to the correct way of doing it or is it just a lucky combination?

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  8. #28
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    My last formula posted seems to work in every respect, have i stumbled on to the correct way of doing it or is it just a lucky combination?
    I hadn't seen this when I posted.

    Just reformat the formula and take a look at it

    =IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),
      IF(AND(D4="",AND(OR(C2={"No Ops","Line Off"}),OR(G2={"No Ops","Line Off"}))),
      IF(OR(J5=2,L5=2,N5=2,R5=2,T5=2,V5=2),"",B31)),
      IF(AND(OR(C2={"Line On","Line On"})),"",""))
    The first test is immediately repeated, and the last test does an OR on the same condition, and then sets it to "" whether TRUE or FALSE.

    Such redundancy can get very expensive on large, complicated spreadsheets, it all is examined on a sheet recalculation, and can slow the calculation down considerably.

    Please don't take this the wrong way, it is offered as constructive criticisim, but I think that you struggle with formula logic. IMO you would benefit from putting the problem on paper and trying to resolve the logic before you commit the formula into Excel, do some decision type tables, or flowcharting, and try and make it as tight as possible before putting in Excel. I also think my formula formatting could help, you see thinsg much more clearly.
    Last edited by Bob Phillips; 12-04-2006 at 04:02 AM.

  9. #29
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,064
    Location
    Good point for all of us Bob.

  10. #30
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Aussiebear
    Good point for all of us Bob.
    Indeed, I am a practitioner myself.

  11. #31
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Bob it takes alot to offend me!, getting anyway getting help, information or criticism from peolple like you is a privilidge not a put down!

    I understand what you have done in the re-format, i pasted my formula in to notepad (as notpad puts everything in to one long line!) and i could see my "copying error" of the two exact same tests at the begining, the statement at the end was a typo it should have read
    IF(AND(OR(C2="Line On",G2="Line On")),"",""))
    as i was getting a value in the cell if Line On appeared, this seemed to solve it and all worked ok.

    You have a valid point of course and you will see from my many posts over time that i sort of build and re-think as i go along - it can be tedious and frustrating not just for me but you guys too!

    The last condition BTW is set to "" whether TRUE or FALSE as i needed a blank if it showed Line on but if it didnt show Line on then the rest of the formula was true - ineptitude on my part!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  12. #32
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    I understand what you have done in the re-format, i pasted my formula in to notepad (as notpad puts everything in to one long line!) ...
    What, you still use Notepad? Why?

    There are dozens of better text editors out there, many free. Examples
    vim
    emacs
    Notepad++
    Notetab Light
    TextPad

  13. #33
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Thanks - For home i will look at those , but work don't allow many types of downloads and of course there is ever the problem with licences and corporate business!

    Regards,
    Simon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  14. #34
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Simon Lloyd
    Thanks - For home i will look at those , but work don't allow many types of downloads ...
    Even for open code such as SourceForge?

    Quote Originally Posted by Simon Lloyd
    and of course there is ever the problem with licences and corporate business!
    Not if it is freeware.

  15. #35
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Yep, they deny all kinds of download here, in fact i was surprised i can download zip attachments off this site!

    If you don't mind Bob i have sent you a PM

    Regards,
    SImon
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •