MS Excel公式更正

时间:2013-08-14 07:00:57

标签: excel

我正在使用以下公式从特定列中搜索某些关键字。但是这一个在Excel中给出的错误可能是Excel仅限于7个嵌套的IF语句。

=IF(ISERROR(SEARCH("*SIPC*",J2,1)),IF(ISERROR(SEARCH("*HIU*",J2,1)),IF(ISERROR(SEARCH("*GMC*",J2,1)),IF(ISERROR(SEARCH("*CNS*",J2,1)),IF(ISERROR(SEARCH("*LCSM*",J2,1)),IF(ISERROR(SEARCH("*RoHC*",J2,1)),IF(ISERROR(SEARCH("*GL1*",J2,1)),IF(ISERROR(SEARCH("*GL3*",J2,1)),IF(ISERROR(SEARCH("*GL2*",J2,1)),IF(ISERROR(SEARCH("*URRC*",J2,1)),IF(ISERROR(SEARCH("*UPHY*",J2,1)),IF(ISERROR(SEARCH("*UHAL*",J2,1)),IF(ISERROR(SEARCH("*UMAC*",J2,1)),"","SIPC"),"HIU"),"GMC"),"CNS"),"LCSM"),"RoHC"),"GL1"),"GL3"),"GL2"),"URRC"),"UPHY"),"UHAL")

任何人都可以建议我为此获得10个以上的嵌套IF语句。

先谢谢.. :))

1 个答案:

答案 0 :(得分:1)

如果可以使用Visual Basic for Applications(VBA),create a macro并在其中定义以下函数:

public function GetCode(s as string) as string
    GetCode = ""
    codes = split( _
        "SIPC|HIU|GMC|CNS|LCSM|RoHC|GL1|GL3|GL2|URRC|UPHY|UHAL|UMAC", "|")

    for each code in codes
        if InStr(s, code) > 0 then 
            GetCode = code
            exit for
        endif
    next

end function

然后,您应该能够访问公式中的函数,如下所示:

= GetCode(J2)