2

我正在使用以下公式从特定列中搜索一些关键字。但是这个在 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 语句的任何替代方案。

提前致谢..:)

4

1 回答 1

1

如果可以接受使用 Visual Basic for Applications (VBA),请创建一个宏并在其中定义以下函数:

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)
于 2013-08-14T07:28:21.207 回答