うまく説明できないちょっと奇妙な問題に直面しています。
CountIfs 式と共にワークシート関数を使用しています。また、配列を使用するために Sumproduct も使用しています。
ただし、配列として定義された 2 つの異なる変数を使用しようとするたびに、間違った結果が得られます。
説明させてください、
私が使用するとき:
Dim lastrow As Long
Dim wsf
lastrow = Sheet2.Cells(Sheet2.Rows.Count, "M").End(xlUp).Row
Set wsf = Application.WorksheetFunction
Doctors = Array("Peter","Sam","Henry")
Emergency = Array("Y","N")
a1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), Doctors, Sheet2.Range("M2:M" & lastrow), Emergency))
a1 の結果が間違っています。
しかし、私がしようとすると:
a1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), Doctors, Sheet2.Range("M2:M" & lastrow), "Y"))
b1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), Doctors, Sheet2.Range("M2:M" & lastrow), "N"))
Final = a1 + b1
または
a1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), "Peter", Sheet2.Range("M2:M" & lastrow), Emergency))
b1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), "Sam", Sheet2.Range("M2:M" & lastrow), Emergency))
c1 = Application.WorksheetFunction.SumProduct(wsf.CountIfs(Sheet2.Range("P2:P" & lastrow), "Henry", Sheet2.Range("M2:M" & lastrow), Emergency))
Final = a1 + b1 + c1
Finalの正しい結果が得られます。
最初の数式を機能させる方法はありますか、または vba では、配列である複数の変数を単一の countifs 関数の基準として使用することはできません。
Doctors 変数と Emergency 変数を宣言する必要があるのではないかと考えましたが、今のところうまくいきません。
助言がありますか?