application.worksheet.function,计算列中的单元格数大于另一列

时间:2015-01-09 10:36:36

标签: excel vba excel-vba vb6

我需要你的帮助!我如何制作一个条件,计算E列中大于或等于列f的单元格,如果其中一列为零则不计数

A       |   B   |   C   |   D   |   E   |   F
--------+-------+-------+-------+-------+--------
A1021   |   A10 |   A   |   RX1 |   99  |   98 '-------> 1'
A1021   |   A10 |   A   |   RX1 |   0   |   98
A1021   |   A10 |   A   |   RX1 |   99  |   98
A1021   |   A10 |   A   |   RX1 |   99  |   0
A1021   |   A10 |   A   |   RX1 |   98  |   98 '------> 1'

答案是2

1 个答案:

答案 0 :(得分:2)

'First variant
'========================================================================
    Sub test()
    Dim N As Long, LastRow As Long, ocell As Range
    N = 0
    LastRow = Cells(Rows.Count, 5).End(xlUp).Row
    For Each ocell In ActiveSheet.Range("E1:E" & LastRow)
        If ocell.Value >= ocell.Offset(, 1).Value And _
            ocell.Value > 0 And ocell.Offset(, 1).Value > 0 Then
        N = N + 1
        End If
    Next
    MsgBox N
    End Sub
'Second variant
'========================================================================
    Sub test2()
    Dim v As Long
    v = Evaluate("sumproduct((E:E>=F:F)*(E:E>0)*(F:F>0))")
    MsgBox v
    End Sub