基于this thread,我使用以下公式:
= INDEX($ B $ 1:$ H $ 1,MATCH(1,B2:H2,0))
它只返回结果中第一个“ 1”的结果。因此,如果存在多个基因,则仅列出第一个。
如何更改公式以包含多个结果?
答案 0 :(得分:0)
您将需要TEXTJOIN()
的阵列版本(Office 365或更高版本):
=TEXTJOIN(", ",TRUE,IF($B2:$H2=1,$B$2:$H$2))
这是一个数组公式,退出编辑模式时必须使用Ctrl-Shift-Enter而不是Enter进行确认。
或连接许多IF语句(所有版本):
=MID(IF(B2=1,", "&$B$1,"")&IF(C2=1,", "&$C$1,"")&IF(D2=1,", "&$D$1,"")&IF(E2=1,", "&$E$1,"")&IF(F2=1,", "&$F$1,"")&IF(G2=1,", "&$G$1,"")&IF(H2=1,", "&$H$1,""),3,999)
如果没有Office 365,则可以使用此UDF来模拟TEXTJOIN并使用上述公式:
Function TEXTJOIN(delim As String, skipblank As Boolean, arr)
Dim d As Long
Dim c As Long
Dim arr2()
Dim t As Long, y As Long
t = -1
y = -1
If TypeName(arr) = "Range" Then
arr2 = arr.Value
Else
arr2 = arr
End If
On Error Resume Next
t = UBound(arr2, 2)
y = UBound(arr2, 1)
On Error GoTo 0
If t >= 0 And y >= 0 Then
For c = LBound(arr2, 1) To UBound(arr2, 1)
For d = LBound(arr2, 1) To UBound(arr2, 2)
If arr2(c, d) <> "" Or Not skipblank Then
TEXTJOIN = TEXTJOIN & arr2(c, d) & delim
End If
Next d
Next c
Else
For c = LBound(arr2) To UBound(arr2)
If arr2(c) <> "" Or Not skipblank Then
TEXTJOIN = TEXTJOIN & arr2(c) & delim
End If
Next c
End If
TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim))
End Function