How to Use COUNTIF to Count Non Empty Cells in Excel
Code:
Sub CountNonBlank()
Cells.Clear
Range("A1:A7") = Application.Transpose(Array("A", "B", "C", "D", "E", "", ""))
Range("A10").Formula = "[COLOR=#ff0000][B]=COUNTIF(A1:A7,""<>"""""")[/B][/COLOR]" ' [COLOR=#ff0000]Rong result[/COLOR]
Range("A12").Formula = "=[COLOR=#006400][B]ROWS(A1:A7) * COLUMNS(A1:A7)-COUNTBLANK(A1:A7)[/B][/COLOR]" ' [B][COLOR=#008000]Wright result[/COLOR][/B]
'''''''''''''''''''''''''''''''''''''''''
With Range("B10")
.Value = "O"
.Font.Name = "Wingdings 2"
End With
With Range("B12")
.Value = "P"
.Font.Name = "Wingdings 2"
End With
''''''''''''''''''''''''''''''''''''''
End Sub