title: VBA Macro and changing date format to mmm-yy
body: <p>I am having problems with an excel macro (VBA) that is meant to grab a date from an excel spreadsheet, subtract one month and reformat it to MMM-YY. Basically I want to take 3/31/2013 and convert it to Feb-13</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Dim ReportDate As Date
  ReportDate = Worksheets("Current").Cells(2, 16) 'ex. 03-31-2013
  prevMonth = Format((Month(ReportDate) - 1) &amp; "/" &amp; Day(ReportDate) &amp; "/" &amp; Year(ReportDate), "mmm") &amp; "-" &amp; Format(ReportDate, "yy")
  Debug.Print prevMonth
  </code></pre>
  
  <p>The result I get is 2/31/2013-13</p>
  
  <p>So I tried changing the prevMonth variable:</p>
  
  <pre><code>prevMonth = Format((Month(ReportDate) - 1) &amp; "/" &amp; Day(ReportDate) &amp; "/" &amp; Year(ReportDate), "mmm-yy")
  </code></pre>
  
  <p>But got just 2/31/2013 again</p>
  
  <p>I tried to declare prevMonth as an Integer or a Date but I get a type mismatch error. I can only declare it as a String but it still doesn't help the program.</p>
  
  <p>Thanks in advance for your help.</p>