I've got a simple macro in which I'm trying to count the values in a column that are less than one. If I select only specific cells with this macro, it works. If I select the entire column, the empty cells are added to the values less than one. I would like to select the entire column and only count the values that are less than I've tried to write it as a single if statement and as a nested if statement, neither one seems to work. Here's my code:
Code: Select all
Sub countRates()
mycount = 0
totalcount = 0
For Each cellvalue In Selection
totalcount = totalcount + 1
If IsNull(cellvalue) = True Then
nullcells = nullcells + 1
ElseIf cellvalue < 1 Then
mycount = mycount + 1
End If
Next
MsgBox "total exchange rates less than 1 is " & _
mycount & " out of " & totalcount
End Sub