excel - Comparing Time values in VBA throws Run-time error 13 'type mismatch' -


am trying compare system time time stored in 2 adjacent cells. tried below comparison of times , works fine...

*this code worked fine* sub btn_click()

 msgbox range("c4"), vbokonly, "test"  dim time1 date  dim time2 date  time1 = time  time2 = timevalue(cells(3, 1).text)  if time1 < time2       msgbox str, vbokonly, "msgif"  else       msgbox str1, vbokonly, "msgelse"  end if 

end sub


but doesn't work!!! if condition throws error saying 'type mismatch'. please help!!!

dim integer dim w integer dim tm1 date dim tm2 date dim tm3 date tm1 = time  = 2 31     tm2 = timevalue(cells(i, 1).text)     tm3 = timevalue(cells(i, 2).text)      if tm1 > tm2 & tm1 < tm3 ' line throws 'type mismatch' error         exit     end if     next   msgbox cells(i, w), vbokonly, "test" 

for sake of so, i'll post answer (in comments) answer (instead of comment). @simoco or @enderland, feel free same , i'll remove answer.

vba not use & operator, nor |. instead, respectively uses andand or.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -