Pregunta

I do not understand why this code doesn't work:

Cells(i, formula_col_index).Value = "=IF(" & time_location & "<>" & time_benchmark & ",""ERROR"",""OK"")"

where

time_location=" 17:00:00",
time_benchmark=" 17:30:00"

It keeps throwing application-defined (or object-defined) error.

Thanks in advance.

¿Fue útil?

Solución

Since your variables time_location and time_benchmark contains string values, you should include them in double quotes when using formula:

Cells(i, formula_col_index).Value = "=IF(""" & time_location & """<>""" & time_benchmark & """,""ERROR"",""OK"")"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top