+ Reply to Thread
Results 1 to 6 of 6

IF and AND not working correctly

  1. #1
    Registered User
    Join Date
    02-22-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    IF and AND not working correctly

    Afternoon guys,
    I work in a hospital and we're trying to relate one spreadsheet to another in order to deduct whether a patient already has a record. To do this im searching for a match of surname and date of birth.

    I created a small model to test the IF(AND forumla on before I implemented it into general use, I am having one problem though the AND statement seems to be working more like an OR statement.

    If you could help me out i'd appreciate it greatly!

    ive attached a screenshot just to show, the values in A1 and G1 are the values being searched for, if both are in the corresponding lists im trying to get HAF to be displayed, otherwise NOT HAF. Currently if one matches then HAF will be shown, but I need both criteia to be fulfilled.

    Thanks for your time, I greatly appreciate any efforts to help me out this tight spot!
    Cheers Jack

    the forumla i currently have is: =IF(AND(ISNA(VLOOKUP(A1,$B$1:$B$20,1,FALSE)),(ISNA(VLOOKUP(G1,$H$1:$H$20,1,FALSE)))),E1,E2)

    (All data in the screenshot is fictional)
    Attached Images Attached Images

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: IF and AND not working correctly

    Your formula should work and give the right result...

    If you press F9, does it work?

    Also, always best to post actual spreadsheet sample, not jpg... so we can diagnose.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    02-22-2010
    Location
    london, england
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: IF and AND not working correctly

    Nope F9 didnt seem to have any effect,
    Heres the spreadsheet im working on as an example, thanks again for your time
    Jack
    Attached Files Attached Files

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: IF and AND not working correctly

    Try:

    =IF(AND(ISNUMBER(MATCH(A1,$B$1:$B$20,FALSE)),(ISNUMBER(MATCH(G1,$H$1:$H$20,FALSE)))),E2,E1)

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: IF and AND not working correctly

    then you should be using OR ie if either is false then give not haf if both true give haf?
    Last edited by martindwilson; 02-22-2010 at 11:13 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

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

    Re: IF and AND not working correctly

    Quote Originally Posted by martindwilson View Post
    then you should be using OR ie if either is false then give not haf if both true give haf?
    I agree with this assessment. Your logic is wrong. The function as you wrote it does exactly what it's supposed to do.

    However! Setting aside the function for a moment, it seems to me from your description that you want to make sure that there is a match for both surname and date of birth together. That is, if you are looking for Jake born on 4/12/78, then your approach as it is now could find some other Jake born on 5/6/59, and also Fred born on 4/12/78, then conclude that the Jake you are looking for already has a record, when in fact he does not. Because your sample data does not seem to have a one-to-one correspondence between patient names and their birthdays, your data may not be organized in such a way as to be able to do this.
    Last edited by 6StringJazzer; 02-22-2010 at 11:56 AM.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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