View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Referencing a fixed cell in VBA using an IF statement

ActiveCell.FormulaR1C1 = "=IF(RC[-4]= ""h"",$s$1,""K"")"

Check it from the immediate window:

? "=IF(RC[-4]=""h"",$s$1,""K"")"
=IF(RC[-4]="h",$s$1,"K")

--
Regards,
Tom Ogilvy


"Neil Crawford" wrote in message
...
Dear all,

I'd be grateful for some advice on how to reference a
fixed cell in a formula that I wish to copy down a row of
cells.

I'm writing some code to put a formula into a cell using
an If statement. I want to pick up a value from a cell
that is anchored ($S$1) but I can't seem to get it
correct in the formula. I've also tried setting it up as
a variable but that doesn't work either. The code below
works except for the "=$S$1" part.

ActiveCell.FormulaR1C1 = "=IF((RC[-4]= ""h,"=$s$1",""K"")"

Any guidance would be gratefully received!

thanks,

Neil