Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MS Excel:IF和嵌套_Excel - Fatal编程技术网

MS Excel:IF和嵌套

MS Excel:IF和嵌套,excel,Excel,有人能帮我使用简单的excel查找功能吗:我如何从表格中提取指定的医生 All other cities and countries Chicago Boston Atlanta California Dallas General Lee John Pediatrics Greg Dermatology Greg Peter Lee O

有人能帮我使用简单的excel查找功能吗:我如何从表格中提取指定的医生

        All other cities
        and countries       Chicago   Boston    Atlanta   California   Dallas

General     Lee               John

Pediatrics  Greg

Dermatology Greg                       Peter      Lee

Optholmol   Greg

Radiology   Mary

Surgery     Greg                                            Mary         Greg

例如,皮肤科和波士顿应返回Peter,但任何其他城市的皮肤科应返回Greg

这是一个公式化的答案(无宏码或VBA):

如果您有这样的表格设置:

在另一张纸或另一个范围内,您希望将其作为输出:

您可以使用此公式,假设输入在A2和B2中,表格在表2中的范围为A2:G8:

=IF(
    IFERROR(
        INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0)),0
    )=0,
    INDEX(Sheet2!B2:B8,MATCH(A2,Sheet2!A2:A8)),
    INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0))
 )
解释:

  • 公式:
    INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0))=0
    将测试给定的一对查找值是否存在医生

    此公式从指定的数组中获取行和列值:

    IFERROR(INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0)),0)=0
                   ^^ array ^^    ^^ match the row ^^    ^^ match the column ^^     ^^ True if no doctor is found
    
  • 如果没有医生,我们可以从“所有其他城市和国家列表”的
    B2:B8
    返回查询:
    索引(Sheet2!B2:B8,MATCH(A2,Sheet2!A2:A8))

  • 如果确实存在,我们可以输出医生:
    INDEX(Sheet2!A2:G8,MATCH(A2,Sheet2!A2:A8,0),MATCH(B2,Sheet2!A2:G2,0))


  • 我试着将它格式化,但我有点困惑,因为你说皮肤科和波士顿应该返回“彼得”,但所有其他城市都返回格雷格?你忘了“Lee”了吗?还是Peter的姓Lee?谢谢你的编辑,你是对的。如果是皮肤科和波士顿,查找应该返回Peter,如果是皮肤科和亚特兰大,查找应该返回Lee,皮肤科和任何其他城市应该返回Greg。谢谢,差不多到了。但是,外科和纽约或皮肤科和纽瓦克的输出为N/A,而不是Greg。适用于除General(例如General和纽约)或General和Chicago(芝加哥)输出之外的所有输出。发现错误,在city之后有一个空格。非常感谢你的帮助。非常感谢。