title: Why does a syntax error appear for a valid formula in VBA code
body: <p>I'm trying to add code to enter a formula to several columns and copy to the end of the row. The VBA works for one of the columns (AB) but I get a syntax error for column AC. The formula works in excel if I enter it manually.
  Any idea why this is and how it can be fixed?</p>
  <pre><code>    Sub AddHeaders()
  
      Dim ws As Worksheet
      Set ws = ActiveSheet
  
      Dim used As Range
      Set used = ws.UsedRange
  
  Dim lastRow As Integer
      lastRow = used.Row + used.Rows.Count - 1
  
  ws.Range(&quot;AB6:AB&quot; &amp; lastRow).Formula = &quot;=IF(ISNUMBER(J6),J6,IF(LEN(J6)=9,DATE(RIGHT(J6,4),LEFT(J6,1),MID(J6,3,2)),IF(LEN(J6)=10,DATE(RIGHT(J6,4),LEFT(J6,2),MID(J6,4,2)))))&quot;
  ws.Range(&quot;AC6:AC&quot; &amp; lastRow).Formula = &quot;=IF(AND(WORKDAY(TODAY(),20)-AB6&lt;=28,WORKDAY(TODAY(),20)-AB6&gt;=0),&quot;yes&quot;,&quot;no&quot;)&quot;
  
  End Sub
  </code></pre>
  <p>Thanks</p>