Consulting

Results 1 to 9 of 9

Thread: How do you create this logic?

  1. #1

    How do you create this logic?

    How do you write this logic?

    If cell c2 contains the words "ABC", then 1, else 0.

    I know IF(xxx,1,0) I just dont know how to write the formula to check whether a cell contains ABC.

    thanks

  2. #2
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    =IF(A1="ABC","Yes","No")

    Something like this.
    "To a man with a hammer everything looks like a nail." - Mark Twain

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    If you need a case sensitive test =EXACT(A1,"abc"), 1, 0)
    Last edited by mikerickson; 12-21-2012 at 10:35 PM.

  4. #4
    For example, if the cell contains "ABC,HELLO,XYZ" (3 items in 1 cell) then how to write a formula that says If this cell contains "ABC" then give me a 1, else 0.

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    EXACT compares strings for likeness (Matching) where you can compare two cell values against each other or compare the cell value against a known value

    It needs to be written either as

    =EXACT(A1,B1) , to compare cells or
    =EXACT("abc",A1), to compare a cell against a predetermined value.

    The results will be True or False.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Maybe something like this =IF(FIND(B1,A1,1),1,0) or =NOT(ISERROR(SEARCH(B1,A1)))
    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)

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Use

    =--ISNUMBER(FIND("ABC",A1))
    case sensitive

    =--ISNUMBER(SEARCH("ABC",A1))
    not case sensitive
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,059
    Location
    Does this return a 1 or 0 Bob?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes the double unary coerces the TRUE/FALSE result.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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