Question

Dear Madams and Sirs,

In my code I make use of an CountIf statement.

Cells(5, 3).Value = Application.WorksheetFunction.CountIf(CR, ">" & yel)

Where:

Dim yel As Double
yel = Cells(2, 5).Value

and:

Dim CR As Range
Set CR = Range("D9:Z26")

The weird thing is: If I use the dynamic criterion (& yel) the code give me a zero as result. And when I use a fixed criterion (">0") the code produces the correct number.

Can anyone tell me what I am doing wrong?

Best regards and thanks in advance,

Wouter

Was it helpful?

Solution

I venture to bet on this guess:
You are not using an English Excel. Your Excel version uses , as decimal mark. The conversion of yel to a string leaves it with a , but the internal engine only understands the English .. Try if this works:

Dim strYel As String
strYel = Replace(CStr(yel), ",", ".")
Cells(5, 3).Value = Application.WorksheetFunction.CountIf(CR, ">" & strYel)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top