View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Graham Whitehead Graham Whitehead is offline
external usenet poster
 
Posts: 72
Default IF formula syntax problem

Alternatively, a long winded way but may help you:

Sub test2()

Dim strEval As String

strEval = Range("C2").Value
If strEval = "Y" Then
Range("D2").Value = 1
ElseIf srteval = 0 Then
Range("D2").Value = 0
End If

End Sub


"Stephen" wrote in message
...
Hi folks,

I'm trying to get my code to insert an IF formula into a cell...

Range("D2").Select
ActiveCell.Formula = "=IF(C2='Y',1,0)"

but I keep getting an object-defined error. I've tried variations of
quotes
and parens. but the best I am able to come up with is having it populate
the
formula as a string. What am I missing?

Thanks.