gpt4 book ai didi

Excel公式: List headers where cell has value

转载 作者:行者123 更新时间:2023-12-04 20:57:45 25 4
gpt4 key购买 nike

如果单元格具有一行中所有单元格的数据,在标题中显示值的公式是什么?该表有许多列。

示例数据:

+----+----+-------+
|One |Two |Output |
+----+----+-------+
|data| |One |
+----+----+-------+
| |data|Two |
+----+----+-------+
|data|data|One,Two|
+----+----+-------+
| | | |
+----+----+-------+

最佳答案

由于 Excel for Mac 2011 的限制,我找不到有效的公式,所以我使用了用户定义函数。

Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, _
ConcatenateRange As Range, Optional Separator As String = ",") As Variant
Dim i As Long
Dim strResult As String
On Error GoTo ErrHandler
If CriteriaRange.Count <> ConcatenateRange.Count Then
ConcatenateIf = CVErr(xlErrRef)
Exit Function
End If
For i = 1 To CriteriaRange.Count
If CriteriaRange.Cells(i).Value = Condition Then
strResult = strResult & Separator & ConcatenateRange.Cells(i).Value
End If
Next i
If strResult <> "" Then
strResult = Mid(strResult, Len(Separator) + 1)
End If
ConcatenateIf = strResult
Exit Function
ErrHandler:
ConcatenateIf = CVErr(xlErrValue)
End Function

然后在使用的单元格中
=ConcatenateIf($A1:$B1, "data", $A$1:$B$1, ",")

归功于 this link

关于Excel公式: List headers where cell has value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43854928/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com