ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   To store the formula in a string (https://www.excelbanter.com/excel-discussion-misc-queries/212054-store-formula-string.html)

pol

To store the formula in a string
 
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


Bob Phillips[_3_]

To store the formula in a string
 
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


--
__________________________________
HTH

Bob

"pol" wrote in message
...
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




pol

To store the formula in a string
 
Still it is not working , Syntax error is coming

"Bob Phillips" wrote:

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


--
__________________________________
HTH

Bob

"pol" wrote in message
...
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





Bob Phillips[_3_]

To store the formula in a string
 
I missed one

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)))"
.Range(.Cells(3, res), .Cells(LastRow, res)).FormulaR1C1 = myFormula
.Columns(res).AutoFit
End With

End Sub


--
__________________________________
HTH

Bob

"pol" wrote in message
...
Still it is not working , Syntax error is coming

"Bob Phillips" wrote:

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


--
__________________________________
HTH

Bob

"pol" wrote in message
...
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







pol

To store the formula in a string
 
thanks a lot

"Bob Phillips" wrote:

I missed one

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)))"
.Range(.Cells(3, res), .Cells(LastRow, res)).FormulaR1C1 = myFormula
.Columns(res).AutoFit
End With

End Sub


--
__________________________________
HTH

Bob

"pol" wrote in message
...
Still it is not working , Syntax error is coming

"Bob Phillips" wrote:

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


--
__________________________________
HTH

Bob

"pol" wrote in message
...
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









All times are GMT +1. The time now is 09:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com