1

我正在尝试在一组重要的列上使用两个参数获取 sumifs(列数不会改变,数据会改变),然后返回最大值或最小值

Function min_or_max(B As Boolean, table As Range, col1 As Range, c1 As Cell, col2 As Range, c2 As Cell)
Dim column As Range

'If B = False Then
min_or_max = 0
For Each column In Range.Columns
If ActiveSheet.WorksheetFunction.SumIfs(Range.column, col1, c1, col2, c2) > min_or_max Then
min_or_max = ActiveSheet.WorksheetFunction.SumIfs(Range.column, col1, c1, col2, c2)
End If
Next column

'Elsif B = True
'min_or_max = 10000000
'For Each column In Range.Columns
'If ActiveSheet.WorksheetFunction.SumIfs(Range.Columns(i), col1, c1, col2, c2) < min_or_max Then
'min_or_max = ActiveSheet.WorksheetFunction.SumIfs(Range.Columns(i), col1, c1, col2, c2)
'End If
'Next column
End Function

在进行最小或最大拆分之前,我无法让 SUMIFS 工作。是因为输入错误的参数吗?(我希望清楚!)

非常感谢能帮助我的人!drf

4

2 回答 2

2

问题WorksheetFunction不是Worksheet 对象,而是Application 对象

所以,你会想使用Application.Worksheetfunction

这一行:

如果活动表.WorksheetFunction.SumIfs(Range.column, col1, c1, col2, c2) > min_or_max 然后

需要看起来像这样:

If Application.WorksheetFunction.SumIfs(Range.column, col1, c1, col2, c2) > min_or_max Then
于 2018-03-08T22:37:37.927 回答
1

现在我正在使用一个非常基本且缓慢的解决方案:

Function max_table(table As range, col1 As range, c1 As range, col2 As range, c2 As range)
Dim i, j As Integer
Dim prov As Integer

max_table = 0
For i = 1 To table.Columns.Count
prov = 0
For j = 1 To table.Rows.Count
    If col1(j).Value = c1.Value And col2(j).Value = c2.Value Then
    prov = prov + table.Cells(j, i).Value
    End If
Next j
If max_table < prov Then
max_table = prov
End If
Next i

End Function
于 2018-03-12T19:50:11.787 回答