计算条件下的单元数

时间:2016-06-24 20:00:30

标签: excel vba excel-vba

我需要计算空白单元格的数量,以及列O中包含小于60的数字的单元格。每次尝试CountIf(Range("O:O"), "")时,我都会得到1048539的值。我期待的方式不止于此。我这样做对吗?我可以计算出小于60的细胞数量。

空白卖出由一个等式设定,如果它们不符合条件,则等于“”。

我现在可以找出我的数据有多少行,但我仍然无法弄清楚如何计算空单元的数量。

这是我正在尝试的。

Sub count()
   Dim blanks As Long
   Dim totalRows As Long
   totalRows = Application.WorksheetFunction.CountA(Range("O:O")) - 1
   For i = 1 To totalRows
        If (Application.WorksheetFunction.isBlank(Cells(i, "O"))) Then
            blanks = blanks + 1
        End If
   Next i
End Sub

我收到以下错误

Object doesn't support this property or method

我认为这与Cells()有关,但我不确定我还能用什么。

2 个答案:

答案 0 :(得分:0)

现在急,但这样的事情可能会有所帮助:

Sub CountCells()

   Dim TotalFilledRows As Long
   Dim TotalRows As Long
   Dim EmptyCells As Long
   Dim CellsWithNumbers As Long

   TotalFilledRows = Application.WorksheetFunction.CountA(Range("O:O"))
   TotalRows = Cells(Rows.count, 15).End(xlUp).Row

   For i = 1 To TotalRows
        If IsEmpty(Cells(i, 15)) Then
            EmptyCells = EmptyCells + 1
        End If

        If Application.WorksheetFunction.IsNumber(Cells(i, 15)) Then
            CellsWithNumbers = CellsWithNumbers + 1
        End If
   Next i

   MsgBox "Total: " & TotalRows & "; Filled: " & TotalFilledRows & "; Empty cells: " & EmptyCells & "; Cells with numbers: " & CellsWithNumbers
End Sub

答案 1 :(得分:0)

openssl enc

由于:

Dim blanks As Long with range(range("o1"), range("o" & rows.count).end(xlup)) blanks = application.countif(.cells,"") - .specialcells(xlcelltypeblanks).count end with 将返回""和空单元格。

countif(.cells,"")将返回空单元格数。

相关问题