题
具有多种条件的Excel中的一个常见解 (此公式计算所有情况,其中A列在C1和B列中的值具有D1中的值):
=SUMPRODUCT((A1:A9=C1)*(B1:B9=D1))
.
i,现在,需要一个函数,即从履行多条条件的行中连接字符串。 http://www.ms-office-forum.net/forum/showthread.php?t=273352
但是,我想检查多个条件 - 因此,使用上面的子节容()技巧。我的问题是:如何定义函数中的参数来获取数组?这是我到目前为止的内容:' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Public Function CONCATIF(Kriterium, Inhalte)
Dim mydic As Object
Dim L As Long
Set mydic = CreateObject("Scripting.Dictionary")
For L = 1 To UBound(Kriterium)
If Kriterium(L, 1) = 1 Then
If Inhalte(L, 1) <> "" Then
mydic(L) = Inhalte(L, 1)
End If
End If
Next
CONCATIF = Join(mydic.items, vbCrLf)
End Function
.
此工作正常,如果我为参数1选择一个列,但只要我包括一个产品公式(如上所述),只有一个变体/双倍具有值1的变型/ kriterium 。
=CONCATIF(A1:A9; E1:E9) Works fine (if column A is 0/1 coded)
=CONCATIF((A1:A9=C1)*(B1:B9=D1); E1:E9) Does not work at all
.
任何建议?谢谢!
解决方案
问题是因为公式:
=CONCATIF((A1:A9=C1)*(B1:B9=D1); E1:E9)
.
通过按 CTRL + SHIFT + ENTER
来调用其他提示
为了完整起见,这里的完整Excel VBA宏将从范围(可能有多个字符串)(可能有多个字符串),如果其他列中的标准匹配。
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Public Function CONCATIF(Kriterium, Inhalte)
Dim mydic As Object
Dim L As Long
Dim C As Long
Dim N As Long
Dim cols As Long
Set mydic = CreateObject("Scripting.Dictionary")
cols = Inhalte.Columns.Count
N = 1
For L = 1 To UBound(Kriterium)
If Kriterium(L, 1) = 1 Then
For C = 1 To cols
If Not IsEmpty(Inhalte(L, C)) Then
mydic(N) = "* " & Inhalte(L, C)
N = N + 1
End If
Next
End If
Next
CONCATIF= Join(mydic.items, vbCrLf)
End Function
.
使用如下 - 并且不要忘记通过 ctrl + shift + 输入
=CONCATIF((A1:A:9="male")*(B1:B9="young"); C1:D9)
.
样本数据
A B C D
01 male young Comment 1 Comment 2
02 male old Comment 3 Comment 4
03 female young Comment 5 Comment 6
04 female old Comment 7 Comment 8
05 male young Comment 9 Comment A
.
结果
* Comment 1
* Comment 2
* Comment 9
* Comment A
.
对于谷歌:这也应作为VerkettenWenn()
找到不隶属于 StackOverflow