Question

The lack of a legible format in excel formulas is making this very hard for me.

I need to write a formula that will:

  • Check if J2 is "No"
  • If not, set value to "N/A"
  • If so, check date in E2 against a given date
  • If after given date, set value to "Pass"
  • If before given date, check if G2 is "Cancel" and K2 is "No", or G2 is "Void" and K2 is "Yes"
  • If true set value to "Fail"
  • If false set value to "Pass"

If I were using Javascript it might look something like this:

function formulasMakeMyHeadHurt(J2,E2,G2,K2,givenDate){

    if(J2=="No"){
        if(E2>givenDate){
            if((G2=="Cancel"&&K2!="No")||(G2=="Void"!="Yes")){
                return "Fail"
            }
            else return "Pass"
        }
        else return "Pass"
    }
    else return "N/A"
}

Here's what I have tried, there's at least one syntax error not to mention some likely logic issues. I've tried formatting the formula different ways while writing it but I keep getting lost in parentheses and cant work out what goes where.

=IF( ISNUMBER(SEARCH(J20,"No"))
           , IF($E20>=DATE(2014,4,10))
               ,"Pass"
           , IF(      OR(   ISNUMBER(FIND("Void",G20))    ,   AND(ISNUMBER(FIND("Cancel",G20)), ISERROR(SEARCH("No",K20)))    )    )
                          ,"Pass"
            ,"Fail")
                )
,"N/A")

same formula without the spacing if that easier on your eyes:

=IF( ISNUMBER(SEARCH(J20,"No")),IF($E20>=DATE(2014,4,10)),"Pass", IF(OR(ISNUMBER(FIND("Void",G20)),AND(ISNUMBER(FIND("Cancel",G20)),ISERROR(SEARCH("No",K20))))),"Pass","Fail")),"N/A")
  • How should this formula be written?
  • Would it be better to use a VBA script?
Was it helpful?

Solution

Here is the formula according to your discription:

=IF(ISNUMBER(SEARCH("No",J2)),IF(E2>=DATE(2014,4,10),"Pass",IF(OR(AND(ISNUMBER(SEARCH("Cancel",G2)),ISNUMBER(SEARCH("No",K2))),AND(ISNUMBER(SEARCH("Void",G2)),ISNUMBER(SEARCH("Yes",K2)))),"Fail","Pass")),"N/A")

or if you'd like, you can use this UDF:

Function formulasMakeMyHeadHurt(J2 As String, E2 As String, _
                            G2 As String, K2 As String, _
                            givenDate As Date) As String
    Dim res As String

    If J2 Like "*No*" Then
        If CDate(E2) >= givenDate Then
            If (G2 Like "*Cancel*" And K2 Like "*No*") Or _
                (G2 Like "*Void*" And K2 Like "*Yes*") Then
                res = "Fail"
            Else
                res = "Pass"
            End If
        Else
            res = "Pass"
        End If
    Else
        res = "N/A"
    End If

    formulasMakeMyHeadHurt = res
End Function

and then call it in any cell like this: =formulasMakeMyHeadHurt(J2,E2,G2,K2,DATE(2014,4,10))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top