LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula for inserting a letter PL Excel Discussion (Misc queries) 3 December 31st 09 04:59 AM
Inserting formula in the cell below Raj[_2_] Excel Worksheet Functions 0 August 1st 09 02:49 AM
Inserting Formula vcprabhu Excel Discussion (Misc queries) 1 April 6th 09 06:55 AM
inserting a formula dstiefe Excel Discussion (Misc queries) 6 August 10th 05 09:33 PM
Formula changes while inserting a row !!!! Sanjeev Unnikrishnan Excel Worksheet Functions 3 April 16th 05 02:45 PM


All times are GMT +1. The time now is 01:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"