Hello everybody. I am modeling some random observations with VBA in Excel. The problem is the use of CountIF in VBA. That function links to data in other sheet and gives different results when is written as follows:
[VBA]Private Sub CommandButton1_Click()
For i = 1 To 10
limit = Range("calculations!B4").Offset(i - 1, 0).Value
' This is incorrect!
freq1 = WorksheetFunction.CountIf(Worksheets("sample").Range("A1:A500"), "<=" & limit)
' This is correct! But I need the previous one
freq2 = WorksheetFunction.CountIf(Worksheets("sample").Range("A1:A500"), "<=1.2888")
Range("calculations!E4").Offset(i - 1, 0).Value = freq1
Range("calculations!F4").Offset(i - 1, 0).Value = freq2
Next i
End Sub[/VBA]
The incorect code calculates all observations in the Range. Looks like ("<=" & limit) is not a String containing the restrictions like ("<=1.2888"). In the attached xls the column Excel must be the same as VBA 1. Any ideas?