Hi Everybody !!

I have a problem with a Macro:

I`m trying to introduce a formula COUNTIF thru the macro but I only get the word "False", not even the formula with an error.

I have used the forumla directly in exel and it run fine.

This is the formula in excel ( spanish ) :

`=SI(F367="On Time";1/CONTAR.SI($X$8:$X$38;"<="&W8);"")`

And this is the macro :

```
Sub Horarios_proxy()
Dim Rango_Rutas As Range
Set Rango_Rutas = Range("B8:C29")
Rango_Rutas.Select
Selection.Copy
Range("B1048575").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
LastRow1 = Range("A" & Rows.Count).End(xlUp).Row + 1
LastRow2 = Range("B" & Rows.Count).End(xlUp).Row
Dim d As String
d = ("D" & LastRow1)
e = ("E" & LastRow1)
f = ("F" & LastRow1)
g = ("G" & LastRow1)
h = ("H" & LastRow1)
i = ("I" & LastRow1)
l = ("L" & LastRow1)
m = ("M" & LastRow1)
Range("D" & LastRow1 & ":D" & LastRow2) = "6:30"
Range("F" & LastRow1 & ":F" & LastRow2) = "=IF((" & e & "<=" & d & "),""On Time"",(" & e & "-" & d & "))"
Range("G" & LastRow1 & ":G" & LastRow2) = "7:15"
Range("I" & LastRow1 & ":I" & LastRow2) = "=IF((" & h & "<=" & g & "),""On Time"",(" & h & "-" & g & "))"
Range("J" & LastRow1 & ":J" & LastRow2) = "=IF(N(" & h & ")<N($Y$8),""Antes de 6:45"",IF(AND(N(" & h & ")>=N($Y$8),N(" & h & ")<=N($Z$8)),""06:45 - 07:15"",IF(AND(N(" & h & ")>N($Z$8),N(" & h & ")<=N($Z$9)),""07:16 - 07:45"",IF(AND(N(" & h & ")>N($Z$9),N(" & h & ")<=N($Z$10)),""07:46 - 08:15"",""Despues de 8:15""))))"
Range("K" & LastRow1 & ":K" & LastRow2) = "1"
Range("M" & LastRow1 & ":M" & LastRow2) = "=IF((" & l & "<=0.791666666666667),""On Time"",(" & l & "-0.791666666666667))"
Range("N" & LastRow1 & ":N" & LastRow2) = "=(" & l & "-" & h & ")"
Range("O" & LastRow1 & ":O" & LastRow2) = "=IF(N(" & l & ")<N($AA$8),""Antes de 15:00"",IF(AND(N(" & l & ")>=N($AA$8),N(" & l & ")<=N($AB$8)),""15:00 - 17:00"",IF(AND(N(" & l & ")>N($AB$8),N(" & l & ")<=N($AB$9)),""17:01 - 19:00"",IF(AND(N(L381)>N($AB$9),N(" & l & ")<=N($AB$10)),""19:01 - 22:00"",""Despues de 22:00""))))"
Range("P" & LastRow1 & ":P" & LastRow2) = "=IF(" & f & "=""On Time"",1,"""")"
Range("Q" & LastRow1 & ":Q" & LastRow2) = "=IF(" & i & "=""On Time"",1,"""")"
Range("R" & LastRow1 & ":R" & LastRow2) = "=IF(" & l & "<=N($AB$9),1,"""")"
[B][COLOR=red]Range("S" & LastRow1 & ":S" & LastRow2) = "=IF(" & f & "=""On Time"",1/COUNTIF($X$8:$X$38," <= "&$W$8),"""")"[/COLOR][/B]
Range("T" & LastRow1 & ":T" & LastRow2) = "=IF(" & i & "=""On Time"",1/COUNTIF($X$8:$X$38," <= "&$W$8),"""")"
Range("U" & LastRow1 & ":U" & LastRow2) = "=IF(" & m & "=""On Time"",1" / "COUNTIF($X$8:$X$38," <= "&$W$8),"""")"
Range("$W$8") = "=MAX(A:A)"
End Sub
```

Display More

The rest of the Macro runs fine it-s just the formula on red.

Any Help or sugestion will be apreciatted.