M
Michael Beckinsale
Hi All,
I am one of those people who have problems with the syntax of complicated
formulas in VBA. Therefore l was hoping to find a simple way of overcoming
the problem. Having input the formula into a cell and using the Record
macro, F2, Enter, method always returns an R1C1 formula in VBA even if the
macro recorder is NOT set to relative.
The TEST code below effectively does what l want but l thought it would be
nice to have the routine in my Personal.xls so that l could easily convert
recorded formulas without having to remember the coding.
The 'FormulaString' coding does not work and returns the formula in the
xlR1C1 format with an additional " at the start and beginning when pasting
"=IF(RC[1]="""",""Empty"",RC[1]" into the InputFormula and Error 2015 when
pasting =IF(RC[1]="""",""Empty"",RC[1])
1) Can anybody tell me what is wrong with the 'FormulaString' code
2) Would it be possible to fully automate the actions ie Record Macro, F2,
Enter etc (possibly using the dreaded SendKeys method)?
TIA
Sub TESTconvertformula()
Dim Result1
Dim IB1
'xxxxx formula created using 'Record Macro' then 'F2' then
'Enter'xxxxxxx
ActiveCell.FormulaR1C1 = "=IF(RC[1]="""",""Empty"",RC[1])"
'xxxxx convert formula to xlA1 and apply '$' referencing
xxxxxxxxxxxxxxxx
Result1 = Application.ConvertFormula("=IF(RC[1]="""",""Empty"",RC[1])",
xlR1C1, xlA1, True)
'xxxxx display result
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MsgBox (Result1)
'xxxxx display result with quotation marks to copy & paste to VBA code
xxxxxxxxxxxxxxxxxxxx
IB1 = InputBox("The formula you need is:", , """" & Result1 & """")
End Sub
Sub FormulaString()
Dim InputFormula
Dim OutputFormula
Dim Result
InputFormula = InputBox("Please enter xlR1C1 formula to convert to xlA1")
Result = Application.ConvertFormula(InputFormula, xlR1C1, xlA1, True)
OutputFormula = InputBox("Copy and paste this result to your VBA code", ,
Result)
End Sub
Regards
Michael Beckinsale
I am one of those people who have problems with the syntax of complicated
formulas in VBA. Therefore l was hoping to find a simple way of overcoming
the problem. Having input the formula into a cell and using the Record
macro, F2, Enter, method always returns an R1C1 formula in VBA even if the
macro recorder is NOT set to relative.
The TEST code below effectively does what l want but l thought it would be
nice to have the routine in my Personal.xls so that l could easily convert
recorded formulas without having to remember the coding.
The 'FormulaString' coding does not work and returns the formula in the
xlR1C1 format with an additional " at the start and beginning when pasting
"=IF(RC[1]="""",""Empty"",RC[1]" into the InputFormula and Error 2015 when
pasting =IF(RC[1]="""",""Empty"",RC[1])
1) Can anybody tell me what is wrong with the 'FormulaString' code
2) Would it be possible to fully automate the actions ie Record Macro, F2,
Enter etc (possibly using the dreaded SendKeys method)?
TIA
Sub TESTconvertformula()
Dim Result1
Dim IB1
'xxxxx formula created using 'Record Macro' then 'F2' then
'Enter'xxxxxxx
ActiveCell.FormulaR1C1 = "=IF(RC[1]="""",""Empty"",RC[1])"
'xxxxx convert formula to xlA1 and apply '$' referencing
xxxxxxxxxxxxxxxx
Result1 = Application.ConvertFormula("=IF(RC[1]="""",""Empty"",RC[1])",
xlR1C1, xlA1, True)
'xxxxx display result
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MsgBox (Result1)
'xxxxx display result with quotation marks to copy & paste to VBA code
xxxxxxxxxxxxxxxxxxxx
IB1 = InputBox("The formula you need is:", , """" & Result1 & """")
End Sub
Sub FormulaString()
Dim InputFormula
Dim OutputFormula
Dim Result
InputFormula = InputBox("Please enter xlR1C1 formula to convert to xlA1")
Result = Application.ConvertFormula(InputFormula, xlR1C1, xlA1, True)
OutputFormula = InputBox("Copy and paste this result to your VBA code", ,
Result)
End Sub
Regards
Michael Beckinsale