Excel: 嵌套 IF 语句如果所有条件都为真 return 所有真值

Excel: Nested IF statement if all condition are true return all true values

我想 return 为所有执行的语句设置多个值。我正在使用以下公式:

=IF(
AND(I4=1,J4=1),"2G",
IF(
AND(Q4=1,V4=1),"3G",
IF(
AND(AC4=1,AG4=1),"4G",
"Other")))

然而,这是 return 嵌套 IF 中的第一个真值。我想 return 所有三个值,2G 3G 4G,如果都为真。结果类似于 concatenated

您有一个 If() 公式,因此一旦找到第一个 TRUE,它就会停止。相反,只需将它们连接起来:

=If(And(I4=1,J4=1),"2G","") & if(and(q4=1,v4=1),"3G","") & if(and(ac4=1,ag4=1),"4G","")

编辑:刚刚意识到这可能会给您留下一个显示“2G3G4G”的单元格,我认为这不是您想要的。如果需要,只需添加逗号分隔符。

edit2:根据您的评论,您可能需要这个:

=If(Or(I4=1,J4=1),"2G","") & if(Or(q4=1,v4=1),"3G","") & if(Or(ac4=1,ag4=1),"4G","")

这将检查 I4=J1 J4=1。如果其中任何一个是 1,它将是 return“2G”。与 Q4V4 相同,如果其中一个是 1,它将 return "3G"。

如果 none 为真,则不获取“2G3G4G”并获取 "other",我建议如下:

=TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE("     "," ",IF(AND(I4=1,J4=1)," 2G"," "),1)," ",IF(AND(Q4=1,V4=1),"3G "," "),3)," ",IF(AND(AC4=1,AG4=1),"4G"," "),5),"     ","other"))

如果您有任何问题,请直接提问 ;)

编辑:

对于在回答时不断变化的问题,我将提供一些 "general" 代码。

如果你想得到所有的解决方案,你可以使用这个:

=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(IF([C_1],[E_1]&" ","  ")&IF([C_2],[E_2]&" ","  ")&...&IF([C_n],[E_n],"  "),REPT("  ",[TC]),[NS]))," ",[ND]),[SR]," ")
  • [C_1],[C_2],...,[C_n] :每个不同表达式的条件
  • [E_1],[E_2],...,[E_n] :表达式本身
  • [TC] : 这个公式
  • 中所有IF的总数
  • [NS] : 如果没有解为真则表达式
  • [ND] : 你想要的新分隔符
  • [SR] : 使用的 "space replacement"

注意:对于此解决方案,您不能使用包含空格的表达式。只需将它们替换为您不使用的符号,例如下划线。 (像 "Exp. 1" 这样的表达式将是 "Exp._1")这将在最后通过 [SR].

改回

因此您的解决方案如下所示:

=SUBSTITUTE(SUBSTITUTE(TRIM(SUBSTITUTE(IF(OR(I4=1,J4=1),"2G ","  ")&IF(AND(Q4=1,V4=1),"3G ","  ")&IF(AND(AC4=1,AG4=1),"4G","  "),REPT("  ",3),"other"))," ","/"),[SR]," ")

因为你的表达式不包含空格,[SR]部分可以跳过:

=SUBSTITUTE(TRIM(SUBSTITUTE(IF(OR(I4=1,J4=1),"2G ","  ")&IF(AND(Q4=1,V4=1),"3G ","  ")&IF(AND(AC4=1,AG4=1),"4G","  "),REPT("  ",3),"other"))," ","/")

如果还有什么问题,尽管问。