title: Excel VBA insert formula
body: <p>i am trying to insert a formula in a cell using vba using a dynamic column reference like this:</p>
  
  <pre><code>Fred = ConvertToLetter(ActiveCell.Column)
  Bob = "=DATE(LEFT(" + Fred + "2,4),MID(" + Fred + "2,5,2),MID(" + Fred + "2,7,2))"
  ActiveCell.FormulaR1C1 = Bob    
  
  Function ConvertToLetter(iCol As Integer) As String
      Dim iAlpha As Integer
      Dim iRemainder As Integer
      iAlpha = Int(iCol / 27)
      iRemainder = iCol - (iAlpha * 26)
      If iAlpha &gt; 0 Then
          ConvertToLetter = Chr(iAlpha + 64)
      End If
      If iRemainder &gt; 0 Then
          ConvertToLetter = ConvertToLetter &amp; Chr(iRemainder + 64)
      End If
  End Function
  </code></pre>
  
  <p>but when it runs the formula ends up with single quotes around the cell and the formula does not work like this:</p>
  
  <pre><code>=DATE(LEFT('AY2',4),MID('AY2',5,2),MID('AY2',7,2))
  </code></pre>
  
  <p>how do i stop the single quotes being added to allow the formula to work correctly?</p>
  
  <p>Thanks</p>