+ Reply to Thread
Results 1 to 11 of 11

Help with IF/OR Formula

  1. #1
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Help with IF/OR Formula

    Hello,

    I need to get a formula where if A1 contains either "1" or "2" then output A1, otherwise output blank.

    What I've tried isn't working. Don't laugh, but this is my best stab at it:

    =IF(ISNUMBER(SEARCH("1",A1))*OR("2",A1),A1,"")

    I'm getting: #VALUE!

    What am I doing wrong?
    Last edited by Ocean Zhang; 01-31-2011 at 02:09 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,284

    Re: Help with IF/OR Formula

    Try:
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Re: Help with IF/OR Formula

    Thanks Marvin! What does ,0,1 mean?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,284

    Re: Help with IF/OR Formula

    Hi,
    Let me read the intent of the formula.
    If there is an error in the formula to Find a 1 in A1 then return a zero, if no error then return a one.
    Do that again for finding a 2 in the number.

    Now add the two numbers above together.
    Could be 0 for no 1 or 2 in the number,
    Could be 1 if only one is a 1 or 2,
    OR the sum could be 2 if both 1 and 2 are in the number.

    Now If the above sum is greater than zero, return the number, else return a blank.

    Some smart guru will most like give you a much shorter formula but this one works.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help with IF/OR Formula

    In terms of condensing you might consider:

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-05-2010
    Location
    S.A
    MS-Off Ver
    Excel 2007
    Posts
    99

    Re: Help with IF/OR Formula

    another code for this:
    Please Login or Register  to view this content.

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help with IF/OR Formula

    The above is slightly different in so far as that it is an exact test rather than a partial (contains) test - the latter requirement is implied by OP.

  8. #8
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Re: Help with IF/OR Formula

    Thanks Donkey and n=b!

    that's exactly what I needed. Donkey, you're right. I needed a search in rather than exact match. Just trying to educate myself: what does the count function do exactly?

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Help with IF/OR Formula

    SEARCH will either return a Number (found) or a #VALUE! error (not found)
    COUNT identifies how many numbers exist in the array of values passed to it.
    In this instance the array of values within the COUNT is the two SEARCH results.
    It follows that if either SEARCH returns a Number the resulting COUNT will be > 0.
    We can use the COUNT result to execute the appropriate part of the IF given only 0 = FALSE (all other numbers = TRUE)

  10. #10
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Help with IF/OR Formula

    Hi,

    the COUNT function is well documented in XL's help which you can access with the F1 key

  11. #11
    Forum Contributor
    Join Date
    05-29-2009
    Location
    Chattanooga, TN
    MS-Off Ver
    2021
    Posts
    205

    Re: Help with IF/OR Formula

    thanks for all the help!

+ 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