title: how to compare time in vba
body: <p>I want to write a macro that compares two times that is available in cells A1 and B1 </p>
  
  <p>I tried to use the following code BUT it gave me <strong><code>"type dismatch"</code></strong> at <code>date1 = TimeValue(Range("A1"))</code></p>
  
  <p>for example, the value at cell A1 like this <code>11/18/2011  10:11:36 PM</code> </p>
  
  <pre><code>dim date1 as date
  dim date2 as date 
  date1 = TimeValue(Range("A1"))
  date1 = TimeValue(Range("B1"))
  if date1 &gt; date2 then
  'do something 
  else 
  'do something else
  end if 
  </code></pre>