以下是我在VBA中尝试计算的代码,希望通过'FormulaResultCount'返回一个计数变量为"3"。为什么不能计算每个单元格中公式所显示的内容;从灰色框中(请参见下面的照片)?
Sub countNonBlanks()
Worksheets("Sheet1").Select
Range("C:C").Select
FormulaResultCount = Selection.SpecialCells(xlCellTypeFormulas).Count
'SpecialCells options from MSFT
' xlCellTypeAllFormatConditions. Cells of any format -4172
' xlCellTypeAllValidation. Cells having validation criteria -4174
' xlCellTypeBlanks. Empty cells 4
' xlCellTypeComments. Cells containing notes -4144
' xlCellTypeConstants. Cells containing constants 2
' xlCellTypeFormulas. Cells containing formulas -4123
' xlCellTypeLastCell. The last cell in the used range 11
' xlCellTypeSameFormatConditions. Cells having the same format -4173
' xlCellTypeSameValidation. Cells having the same validation -4175
' xlCellTypeVisible. All visible cells
'
End Sub
参考公式如下:
注意:由于在动态工作时我将有更多的单元格,循环可能会使过程变慢太多。此外,我尝试使用CountA没有结果。
FormulaResultCount
被赋予了什么值? - Doug Glancy