+ Reply to Thread
Results 1 to 5 of 5

if AND statement. Displays ERROR

  1. #1
    Registered User
    Join Date
    02-10-2012
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2010
    Posts
    9

    if AND statement. Displays ERROR

    IF(AND(SEARCH("U",$G25),AND(TIMEVALUE("12:00")>=$H25,TIMEVALUE("12:00")<$I25)),"x"," ")

    I want the target cell to display x if a time falls in between a time range, and it works fine. The problem is when I try combining the two formulas. I'm trying to make it create an x if "U" is found in a certain cell AND a time falls between a certain range. Both work fine on their own, but when I combine the two formulas into one AND statement I find trouble.

    The formula works for when it meets the condition, and creates an x. The problem is that if it doesn't meet the conditions it creates an error rather than the space. I have temporarily resolved this by using:
    =IFERROR(IF(AND(SEARCH("U",$G13),AND(TIMEVALUE("23:30")>=$H13,TIMEVALUE("23:30")<$I13)),"x"," ")," ")

    But that is not ideal.

    I would be extremely grateful for assistance on the problem!

  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,814

    Re: if AND statement. Displays ERROR

    The problem is that SEARCH returns an error if the letter doesn't exist, so the way to get round it is like this:

    IF(ISERROR(SEARCH("U",$G25)),"",IF(AND(TIMEVALUE("12:00")>=$H25,TIMEVALUE("12:00")<$I25),"x",""))

    or you could do it like this:

    IF(ISNUMBER(SEARCH("U",$G25)),IF(AND(TIMEVALUE("12:00")>=$H25,TIMEVALUE("12:00")<$I25),"x",""),"")

    Hope this helps.

    Pete
    Last edited by Pete_UK; 02-11-2012 at 09:16 AM.

  3. #3
    Registered User
    Join Date
    02-10-2012
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: if AND statement. Displays ERROR

    Thanks Pete, you are absolutely amazing! This solved my issue, thank you!

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: if AND statement. Displays ERROR

    A failed SEARCH will always return a #VALUE error (see Excel's help). Try using the IFERROR in front of the SEARCH function to return FALSE...

    =IF(AND(IFERROR(SEARCH("U",$G25),FALSE),AND(TIMEVALUE("12:00")>=$H25,TIMEVALUE("12:00")<$I25)),"x"," ")

  5. #5
    Registered User
    Join Date
    02-10-2012
    Location
    Syracuse, NY
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: if AND statement. Displays ERROR

    Quote Originally Posted by dangelor View Post
    A failed SEARCH will always return a #VALUE error (see Excel's help). Try using the IFERROR in front of the SEARCH function to return FALSE...

    =IF(AND(IFERROR(SEARCH("U",$G25),FALSE),AND(TIMEVALUE("12:00")>=$H25,TIMEVALUE("12:00")<$I25)),"x"," ")
    Thanks for your reply dangelor, that will definitely help me in the future.

+ 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