1

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.

Community
  • 1
  • 1
7raiden7
  • 319
  • 1
  • 4
  • 16

1 Answers1

7

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"")"
Dmitry Pavliv
  • 35,333
  • 13
  • 79
  • 80
  • 1
    omg im not thinking straight today.. haha I have ran out of votes but a definite +1 and -1 for me being a complete idiot on this one –  Mar 04 '14 at 15:51