ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error when using macro to write formula to cell (https://www.excelbanter.com/excel-programming/293993-error-when-using-macro-write-formula-cell.html)

Patti[_3_]

Error when using macro to write formula to cell
 
When typed directly in cell L11, this formula does what I want:
=IF(E11<0.25,"",E11-TIME(0,16,0))

When I go to the Immediate Window and type ? range ("L11").FormulaR1C1, the
following is returned: =IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))

So I tried to create a procedure using that -

Range("L11").Activate
ActiveCell.FormulaR1C1 = "=IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))"

.... and get the error "Run-time error '1004': Application-defined or
object-defined error"

Can anyone tell me what I am doing wrong?

TIA, Patti




Frank Kabel

Error when using macro to write formula to cell
 
Hi
try
ActiveCell.FormulaR1C1 = "=IF(RC[-7]<0.25,"""",RC[-7]-TIME(0,16,0))"

--
Regards
Frank Kabel
Frankfurt, Germany


Patti wrote:
When typed directly in cell L11, this formula does what I want:
=IF(E11<0.25,"",E11-TIME(0,16,0))

When I go to the Immediate Window and type ? range
("L11").FormulaR1C1, the following is returned:
=IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))

So I tried to create a procedure using that -

Range("L11").Activate
ActiveCell.FormulaR1C1 = "=IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))"

... and get the error "Run-time error '1004': Application-defined or
object-defined error"

Can anyone tell me what I am doing wrong?

TIA, Patti



Chip Pearson

Error when using macro to write formula to cell
 
Patti,

Try
ActiveCell.FormulaR1C1 =
"=IF(RC[-7]<0.25,"""",RC[-7]-TIME(0,16,0))"

Note that additional quotes inside the formula.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Patti" wrote in message
...
When typed directly in cell L11, this formula does what I want:
=IF(E11<0.25,"",E11-TIME(0,16,0))

When I go to the Immediate Window and type ? range

("L11").FormulaR1C1, the
following is returned: =IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))

So I tried to create a procedure using that -

Range("L11").Activate
ActiveCell.FormulaR1C1 =

"=IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))"

... and get the error "Run-time error '1004':

Application-defined or
object-defined error"

Can anyone tell me what I am doing wrong?

TIA, Patti






Patti[_3_]

Error when using macro to write formula to cell
 
Frank, that extra set of quotes did the trick. Thank you very much - I
never would have come up with that on my own!

Patti


"Frank Kabel" wrote in message
...
Hi
try
ActiveCell.FormulaR1C1 = "=IF(RC[-7]<0.25,"""",RC[-7]-TIME(0,16,0))"

--
Regards
Frank Kabel
Frankfurt, Germany


Patti wrote:
When typed directly in cell L11, this formula does what I want:
=IF(E11<0.25,"",E11-TIME(0,16,0))

When I go to the Immediate Window and type ? range
("L11").FormulaR1C1, the following is returned:
=IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))

So I tried to create a procedure using that -

Range("L11").Activate
ActiveCell.FormulaR1C1 = "=IF(RC[-7]<0.25,"",RC[-7]-TIME(0,16,0))"

... and get the error "Run-time error '1004': Application-defined or
object-defined error"

Can anyone tell me what I am doing wrong?

TIA, Patti






All times are GMT +1. The time now is 01:58 PM.

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