ExcelのVBAにマトリックス(?)を渡す
質問
複数の条件で複数の条件でExcelの1つの一般的な解決策がこのようになります (この式は、C1と列Bの値がD1の値を持つすべてのケースをカウントします):
=SUMPRODUCT((A1:A9=C1)*(B1:B9=D1))
.
iは、複数の条件を満たす線からの文字列を連結する関数を必要とします。 one 条件に最適な解決策があります。 > http://www.ms-office-forum.net/forum/showthread.php?t=273352
iは、複数の条件を確認したいと思う - したがって、上からsubproduct()トリックを使用します。私の問題は次のとおりです。配列を取得するための関数内のパラメータを定義する必要がありますか?これが私がこれまでに得たものです:
' **********************************************************************
' 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つ選択するとうまく機能しますが、(上のように)製品式を含めるとすぐに、値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 + を押すことで呼び出す必要があります 他のヒント
完全性のために、他の列の基準が一致している場合、範囲からの文字列を連結するための完全なExcel VBAマクロが完全な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
.
Googleの場合:これはVerkettenwenn()
としても見つけられるものとします。所属していません StackOverflow