![]() |
Formula appearing instead of result
I have the following code in a macro
If Range("g" & x - 1) 2 Then 'charlie if ActiveCell.FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" ElseIf Range("g" & x - 1) < 2 Then ActiveCell.FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" Else: ActiveCell.Value = "2 yellow" End If In the active cell, I am getting "=R[-1]C[-3]-RC[-3]" showing up instead of the result. I've tried chaning formatting to general, text, number, etc. Sometimes it works sometimes it doesn't. The last time I ran the macro, I got a mix of success and failure with the cells formatted as text. Any ideas why this is happening? TIA Papa J |
Formula appearing instead of result
Hi,
The cells may be formatted as text so try this. Also note your code can be simplified to this version If Range("g" & x - 1) < 2 Then 'charlie if With ActiveCell .NumberFormat = "General" .FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" End With Else ActiveCell.Value = "2 yellow" End If -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Papa Jonah" wrote: I have the following code in a macro If Range("g" & x - 1) 2 Then 'charlie if ActiveCell.FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" ElseIf Range("g" & x - 1) < 2 Then ActiveCell.FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" Else: ActiveCell.Value = "2 yellow" End If In the active cell, I am getting "=R[-1]C[-3]-RC[-3]" showing up instead of the result. I've tried chaning formatting to general, text, number, etc. Sometimes it works sometimes it doesn't. The last time I ran the macro, I got a mix of success and failure with the cells formatted as text. Any ideas why this is happening? TIA Papa J |
Formula appearing instead of result
Thanks Mike!
"Mike H" wrote: Hi, The cells may be formatted as text so try this. Also note your code can be simplified to this version If Range("g" & x - 1) < 2 Then 'charlie if With ActiveCell .NumberFormat = "General" .FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" End With Else ActiveCell.Value = "2 yellow" End If -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. "Papa Jonah" wrote: I have the following code in a macro If Range("g" & x - 1) 2 Then 'charlie if ActiveCell.FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" ElseIf Range("g" & x - 1) < 2 Then ActiveCell.FormulaR1C1 = "=R[-1]C[-3]-RC[-3]" Else: ActiveCell.Value = "2 yellow" End If In the active cell, I am getting "=R[-1]C[-3]-RC[-3]" showing up instead of the result. I've tried chaning formatting to general, text, number, etc. Sometimes it works sometimes it doesn't. The last time I ran the macro, I got a mix of success and failure with the cells formatted as text. Any ideas why this is happening? TIA Papa J |
All times are GMT +1. The time now is 06:29 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com