Excel 条件连接

问题描述 投票:0回答:3

我有几列试图根据条件语句进行连接。我的专栏看起来像:

Col 1    Col 2    Col 3    Col 4    Col 5
  73      NA       NA       NA       NA 

我正在尝试连接没有“NA”或空白的单元格。我有以下代码行:

=IF(OR(B2<>"",B2<>"NA"),CONCATENATE(A2,",",B2),IF(OR(C2<>"",C2<>"NA"),CONCATENATE(A2,",",B2,",",C2),IF(OR(D2<>"",D2<>"NA"),CONCATENATE(A2,",",B2,",",C2,",",D2),IF(OR(E2<>"",E2<>"NA"),CONCATENATE(A2,",",B2,",",C2,",",D2,",",E2),0))))

期望的输出是

73

但是,我不断

 73, NA

注意:第 1 列始终有一个数字。

excel-formula excel-2010
3个回答
4
投票

试试这个:

=LEFT(IF(AND(A1<>"",A1<>"NA"),A1 & ",","") & IF(AND(B1<>"",B1<>"NA"),B1 & ",","") &IF(AND(C1<>"",C1<>"NA"),C1 & ",","") &IF(AND(D1<>"",D1<>"NA"),D1 & ",","") &IF(AND(E1<>"",E1<>"NA"),E1 & ",",""),LEN(IF(AND(A1<>"",A1<>"NA"),A1 & ",","") & IF(AND(B1<>"",B1<>"NA"),B1 & ",","") &IF(AND(C1<>"",C1<>"NA"),C1 & ",","") &IF(AND(D1<>"",D1<>"NA"),D1 & ",","") &IF(AND(E1<>"",E1<>"NA"),E1 & ",","") )-1)

enter image description here


编辑:

看起来好像您的数据按列顺序加载。 您可以将公式简化为:

=A1 & IF(AND(B1<>"",B1<>"NA"),"," & B1,"")& IF(AND(C1<>"",C1<>"NA"),"," & C1,"")& IF(AND(D1<>"",D1<>"NA"),"," & D1,"")& IF(AND(E1<>"",E1<>"NA"),"," & E1,"")

编辑#2

如果您使用的是 Office 365 Excel,则使用 TextJoin 作为数组公式:

=TEXTJOIN(",",TRUE,IF((A1:E1<>"NA")*(A1:E1<>""),A1:E1,""))

作为数组公式,退出编辑模式时需要使用 Ctrl-Shift-Enter 确认,而不是 Enter。 如果操作正确,Excel 会在公式周围加上

{}


1
投票

Excel 2019+ 中的 TEXTJOIN 函数允许范围作为参数,与数组公式组合成为条件 CONCATENATE 或“CONCATENATEIF”。

=TEXTJOIN(", ", TRUE, IF(A1:D1<>"NA", A1:D1, ""))

不要只按 Enter,而是按 Shift + Ctrl + Enter。这会将其保存为数组公式,而不是简单的公式。它在公式框中的显示会有所不同。

{=TEXTJOIN(", ", TRUE, IF(A1:D1<>"NA", A1:D1, ""))}

有关数组公式的更多信息请参见此处。 数组公式的指南和示例


0
投票

B2 是“NA”,反转你的

OR
中的逻辑。

© www.soinside.com 2019 - 2024. All rights reserved.