title: VBA - Date Format "mm/dd/yyyy"
body: <p>My excel file format for date is <code>Mar 30 2016 10:12:27:396AM</code> i want to change the format to <code>mm/dd/yyyy</code>. but i'm having an error on my code..</p>
  
  <blockquote>
    <p>Run-time error '13': Type mismatch</p>
  </blockquote>
  
  <p>this is the line i got the error  <code>SecondDate = Trim(Sheet2.Range("B" &amp; RowNo).Value)</code></p>
  
  <p><strong>Note</strong>: The data from Column A and B are dates </p>
  
  <p>My Code:</p>
  
  <pre><code>Dim Result, RowNo As Long
  Dim FirstDate As Variant
  Dim SecondDate As Variant
  
  RowNo = 2
  
      FirstDate = Trim(Sheet2.Range("A" &amp; RowNo).Value)
      SecondDate = Trim(Sheet2.Range("B" &amp; RowNo).Value)
      FirstDate = Format(FirstDate, "mm/dd/yyyy")
      SecondDate = Format(SecondDate, "mm/dd/yyyy")
  
      Do Until Sheet2.Cells(RowNo, 1) = ""
  
      FirstDate = Sheet2.Cells(RowNo, 1)
      SecondDate = Sheet2.Cells(RowNo, 2)
  
          If DateDiff("d", FirstDate, SecondDate) &gt;= 15 Then
          Sheet2.Cells(RowNo, 3) = "1"
          Sheet2.Cells(RowNo, 4) = "2"
  
      End If
  
     RowNo = RowNo + 1
     Loop
  </code></pre>
  
  <p>i do feel like im in the right path..am i missing something? </p>
  
  <p><strong>Update</strong>: My script will get the data from <code>Column A</code> and <code>Column B</code> and using the <em>DateDiff</em> function i will <em>subtract</em> both columns if the difference is &lt;15 tag it from <code>Column C and D</code> as <code>1, 2</code> </p>
  
  <p><strong>note:</strong></p>
  
  <ul>
  <li>i only subtract the days from both columns.. but is it possible to subtract both days and years?</li>
  <li>it's working if i use the format mm/dd/yyyy in the excel but if i use other format i got the error <em>mismatch</em></li>
  </ul>
  
  <p><strong>Updated 2</strong>:</p>
  
  <pre><code>       Column A            | Column B                   | Column C
  Mar 1  2016 10:12:27:396AM | Mar 30 2016 10:12:27:396AM |
  Mar 1  2016 10:12:27:396AM | Mar 30 2016 10:12:27:396AM |
  </code></pre>
  
  <p>in my file this is the date format, if you try this as sample data it won't work maybe because VBA doesnt recognize this as dateformat?</p>