View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Storing formula in cell

SessionLeakHrs = "=SumIf(Indirect("S" &Q5+1 &":S" &R5+1),"<"
&V2,Indirect("R" &Q5+1 &":R" &R5+1))"


There are a couple of ways to interpret exactly which formula you want from
the above. Given the set up you show in the statement above, can you show us
sample values for Q5, R5 and V5 and then show us the formula you want to end
up in the cell for those given values?

--
Rick (MVP - Excel)


"Cinco" wrote in message
...
Rick,
Here is a test macro with the formula that I am trying to save in a cell.
The formula needs to be executable in the cell not just a text string. I
can't get it to work - I tried replacing all the quotes in the formula
with
double quotes but it still wouldn't work. In this example, I am showing
the
actual real formula without any double quotes. Give it a try and see if
you
can figure out what needs to be done. Maybe it is too complicated a
formula
to save!!

Jim

Sub TestStoreFormula()

' Initialize Night Begin/End Date/Time cells/values

NightStartDateNTime = "=$B$2+$A$1"
Range("$B$1").Select
ActiveCell.Formula = NightStartDateNTime
NightEndDateNTime = "=$B$1+0.99929"
Range("$C$2").Select
ActiveCell.Formula = NightEndDateNTime


' TestStoreFormula Macro
' Macro recorded 7/24/2009

' Need different formula for calculating Leak Hrs for Session Charts than
for Night Charts

SessionLeakHrs = "=SumIf(Indirect("S" &Q5+1 &":S" &R5+1),"<"
&V2,Indirect("R" &Q5+1 &":R" &R5+1))"
Range("$W$2").Select
ActiveCell.Formula = SessionLeakHrs

End Sub

"Rick Rothstein" wrote:

Your originally posted formula looks like it has an extra quote mark at
the
very end... try removing the last character (which is a quote mark) and
see
if that does it for you.

--
Rick (MVP - Excel)


"Cinco" wrote in message
...
Rick,

No, I want it to be executable.

Jim

"Rick Rothstein" wrote:

When you save "save in a cell"... do you mean as text so it doesn't
get
evaluated? If yes, just leave it as it is and put an apostrophe in
front
of
the equal sign.

--
Rick (MVP - Excel)


"Cinco" wrote in message
...
I want to save the following formula in a cell:

=Sumif(Indirect("S" &Q5+1 &":S" &R5),"<" &V2,Indirect("R" &Q5+1
&":R"
&R5))"


I've tried using double "s at various places but with no success.
The
formula that is saved does not match the one above. Any ideas on
what
the
right combination of " is for this formula so I can save a copy in a
cell?
Thanks.

Jim