これは、「FormulaResultCount」から「3」のカウント戻り変数を返すことを期待して、VBA でカウントしようとしているコードです。各セル内の数式によって視覚的に返されるものを数えることができないのはなぜですか。灰色のボックスから(下の写真を参照)?
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を使用してみました。