ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel inserts single quote marks into formula (https://www.excelbanter.com/excel-programming/361403-excel-inserts-single-quote-marks-into-formula.html)

Max Bialystock[_2_]

Excel inserts single quote marks into formula
 
When I use vba to insert this formula:
Sub Macro1()
ActiveCell.FormulaR1C1 = "=IF(F12=0," & Chr(34) & Chr(34) & Chr(34) &
Chr(34) & ",IF(F12<0.3,0.3-F12," & Chr(34) & Chr(34) & Chr(34) & Chr(34) &
"))"

End Sub
I get this result:
=IF('F12'=0,"""",IF('F12'<0.3,0.3-'F12',""""))

How do I stop Excel from inserting the single quotation marks?

Cheers,
Max



Bob Phillips[_6_]

Excel inserts single quote marks into formula
 
You cannot use FormulaR1C1 with an A1 style formula. Try

ActiveCell.Formula = "=IF(F12=0," & Chr(34) & Chr(34) & Chr(34) & _
Chr(34) & ",IF(F12<0.3,0.3-F12," & Chr(34) & Chr(34) & Chr(34) & _
Chr(34) & "))"

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Max Bialystock" wrote in message
...
When I use vba to insert this formula:
Sub Macro1()
ActiveCell.FormulaR1C1 = "=IF(F12=0," & Chr(34) & Chr(34) & Chr(34) &
Chr(34) & ",IF(F12<0.3,0.3-F12," & Chr(34) & Chr(34) & Chr(34) & Chr(34) &
"))"

End Sub
I get this result:
=IF('F12'=0,"""",IF('F12'<0.3,0.3-'F12',""""))

How do I stop Excel from inserting the single quotation marks?

Cheers,
Max





Ardus Petus

Excel inserts single quote marks into formula
 
FormulaR1C1 expects R1C1 references.

Enter Activecell.Formula = "=IF(F12=0,"""",IF(F12<0.3,0.3-F12,"""")"

HTH
--
AP

"Max Bialystock" a écrit dans le message de news:
...
When I use vba to insert this formula:
Sub Macro1()
ActiveCell.FormulaR1C1 = "=IF(F12=0," & Chr(34) & Chr(34) & Chr(34) &
Chr(34) & ",IF(F12<0.3,0.3-F12," & Chr(34) & Chr(34) & Chr(34) & Chr(34) &
"))"

End Sub
I get this result:
=IF('F12'=0,"""",IF('F12'<0.3,0.3-'F12',""""))

How do I stop Excel from inserting the single quotation marks?

Cheers,
Max






All times are GMT +1. The time now is 04:21 PM.

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