P
pol
Please help to store the followng formula in a string . I did the following
ways but not working . The purpose of the formula to convert string into
date format. The formlula is working independantly. But it didnot working
when I am trying to store in a variable.
myFormula =
"=IF(LEFT(CELL("format",RC[1]),1)="D",RC[1],DATE(LEFT(RC[1],4),MID(RC[1],5,2),RIGHT(RC[1],2)))"
Sub sizeonly()
Dim res As Variant
Dim wks As Worksheet
Dim LastRow As Long
Dim myFormula As String
Set wks = ActiveSheet
With wks
res = Application.Match("DATE", .Rows(2), 0)
LastRow = .Cells(.Rows.Count, res).End(xlUp).Row
.Columns(res).Insert
'add header in row 1
.Cells(2, res).Value = "YEAR"
myFormula =
"=IF(LEFT(CELL("format",RC[1]),1)="D",RC[1],DATE(LEFT(RC[1],4),MID(RC[1],5,2),RIGHT(RC[1],2)))" 'Here is not working pls help
.Range(.Cells(3, res), .Cells(LastRow, res)).FormulaR1C1 = myFormula
.Columns(res).AutoFit
End With
End Sub
With thanks
Polachan Paily
ways but not working . The purpose of the formula to convert string into
date format. The formlula is working independantly. But it didnot working
when I am trying to store in a variable.
myFormula =
"=IF(LEFT(CELL("format",RC[1]),1)="D",RC[1],DATE(LEFT(RC[1],4),MID(RC[1],5,2),RIGHT(RC[1],2)))"
Sub sizeonly()
Dim res As Variant
Dim wks As Worksheet
Dim LastRow As Long
Dim myFormula As String
Set wks = ActiveSheet
With wks
res = Application.Match("DATE", .Rows(2), 0)
LastRow = .Cells(.Rows.Count, res).End(xlUp).Row
.Columns(res).Insert
'add header in row 1
.Cells(2, res).Value = "YEAR"
myFormula =
"=IF(LEFT(CELL("format",RC[1]),1)="D",RC[1],DATE(LEFT(RC[1],4),MID(RC[1],5,2),RIGHT(RC[1],2)))" 'Here is not working pls help
.Range(.Cells(3, res), .Cells(LastRow, res)).FormulaR1C1 = myFormula
.Columns(res).AutoFit
End With
End Sub
With thanks
Polachan Paily