View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Inserting Formula

when using double quotes inside a string, you need to double the double
quotes

Dim sForm as String
sForm = "=IF(O2=""H"",""On Time"", IF(AND(O2=""M"",N2" & _
"<0),""Late"",IF(AND(O2=""M"",N20),""Early"") ))"
ActiveCell.Formula = sForm

demo'd from the immediate window:

sform = "=IF(O2=""H"",""On Time"", IF(AND(O2=""M"",N2" & _
"<0),""Late"",IF(AND(O2=""M"",N20),""Early"") ))"
? sform
=IF(O2="H","On Time",
IF(AND(O2="M",N2<0),"Late",IF(AND(O2="M",N20),"Ea rly")))

--
Regards,
Tom Ogilvy


"jmdaniel" wrote in message
...
I am trying to insert a formula in a macro, then auto fill this formula to

the last row with data in it. So far, (with the first cell the formula goes
in being P2):

Range("P2").Select
ActiveCell.Formula = "=IF(O2="H","On Time",

IF(AND(O2="M",N2<0),"Late",IF(AND(O2="M",N20),"Ea rly")))
Sub autofill()
LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("D2").autofill Destination:=.Range("D2:D" & LastRow) _
, Type:=xlFillDefault
End With


Column O has H or M as text, signifying Hit or Miss, and column N has the

number of days a shipment was late, on time, or early.

The error I got, I believe was a compile error, "expecting an end" (slight

paraphrase), and the "H" was highlighted. I hope I have given enough info,
and that somebody can give me a hand!

Thanks,
Jeff