i am trying to insert a formula in a cell using vba using a dynamic column reference like this:
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 > 0 Then
ConvertToLetter = Chr(iAlpha + 64)
End If
If iRemainder > 0 Then
ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
End If
End Function
but when it runs the formula ends up with single quotes around the cell and the formula does not work like this:
=DATE(LEFT('AY2',4),MID('AY2',5,2),MID('AY2',7,2))
how do i stop the single quotes being added to allow the formula to work correctly?
Thanks