SUMPRODUCT WorksheetFunction 中的(条件)
(Condition) in SUMPRODUCT WorksheetFunction
实际上,我需要 运行 使用变体数组的 COUNTIFS WorksheetFunction,但我猜这在 VBA 中是不可能的。另一种方法是在 VBA 中编写我自己的 COUNTIFS 函数,但我想知道是否可以在 VBA...
中编写以下 SUMPRODUCT 函数
=SUMPRODUCT(--(Table1[Col1]="Something"),--(Table1[Col2]="Something"))
如果我们能做到这一点,那么我就不需要编写额外的函数了。不确定哪个会更快。
如果您只是在寻找可操作的 COUNTIFS function using structured table references then the ListObject object 并且它的属性是正确的选择。
Sub dermal()
Dim hdr1 As Long, hdr2 As Long, cntif As Long
Dim str As String, app As Application
Set app = Application
With Worksheets("Sheet1").ListObjects("Table1")
hdr1 = app.Match("Col1", .HeaderRowRange.Rows(1), 0)
hdr2 = app.Match("Col2", .HeaderRowRange.Rows(1), 0)
str = "something"
cntif = app.CountIfs( _
.ListColumns(hdr1).DataBodyRange, str, _
.ListColumns(hdr2).DataBodyRange, str)
Debug.Print cntif
End With
Set app = Nothing
End Sub
较新的 COUNTIFS 比同类 SUMPRODUCT function 快得多;通常需要 30% 的时间来完成等效操作,即使在使用完整的列范围引用时也是如此,而 SUMPRODUCT 已被削减到数据的最小范围。
如果您绝对需要每毫秒挤出一次并需要内存中处理的变体数组,那么我建议使用 Filtering 2D Arrays in Excel VBA by assylias.[=14 中的过滤方法的 class 结构=]
实际上,我需要 运行 使用变体数组的 COUNTIFS WorksheetFunction,但我猜这在 VBA 中是不可能的。另一种方法是在 VBA 中编写我自己的 COUNTIFS 函数,但我想知道是否可以在 VBA...
中编写以下 SUMPRODUCT 函数=SUMPRODUCT(--(Table1[Col1]="Something"),--(Table1[Col2]="Something"))
如果我们能做到这一点,那么我就不需要编写额外的函数了。不确定哪个会更快。
如果您只是在寻找可操作的 COUNTIFS function using structured table references then the ListObject object 并且它的属性是正确的选择。
Sub dermal()
Dim hdr1 As Long, hdr2 As Long, cntif As Long
Dim str As String, app As Application
Set app = Application
With Worksheets("Sheet1").ListObjects("Table1")
hdr1 = app.Match("Col1", .HeaderRowRange.Rows(1), 0)
hdr2 = app.Match("Col2", .HeaderRowRange.Rows(1), 0)
str = "something"
cntif = app.CountIfs( _
.ListColumns(hdr1).DataBodyRange, str, _
.ListColumns(hdr2).DataBodyRange, str)
Debug.Print cntif
End With
Set app = Nothing
End Sub
较新的 COUNTIFS 比同类 SUMPRODUCT function 快得多;通常需要 30% 的时间来完成等效操作,即使在使用完整的列范围引用时也是如此,而 SUMPRODUCT 已被削减到数据的最小范围。
如果您绝对需要每毫秒挤出一次并需要内存中处理的变体数组,那么我建议使用 Filtering 2D Arrays in Excel VBA by assylias.[=14 中的过滤方法的 class 结构=]