View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Put a formula in a Cell through VBA


I guess I am not entirely sure what problem you are actually having. First,
I'm guessing where you say "This is my actual code", either you meant to
include a cell reference in front of the word "formula", or you meant to
include a dot in front of it (further assuming that there are surrounding
With/EndWith statements for the dot to reference to), or formula is variable
name that will be assigned later on to the Formula property of some cell
reference. The String value you show assigns without error to the Formula
property of a cell reference. If the cell indicated by CurRow of column E
contains this...

< 0.005

(note the space between the less than symbol and the first 0), then the
formula placed by the code displays 0.0025 as it should (the rest of the
formula appears to work correctly as well)... is that internal space causing
your problem by any chance?

--
Rick (MVP - Excel)


"YouWontSpamThisAdress" wrote in
message ...
Hi Rick,

That is what I did... the cut-paste indicated is the result in the actual
cell...

This is my actual code :
formula = "=IF(E" & CurRow & "=""< 0.005"",0.0025,IF(F" & CurRow & "0,F"
& CurRow & " , E" & CurRow & "))"

Thanks

"Rick Rothstein" a écrit dans le
message de news: ...
If you assign the string representation of your formula to the Formula
property of the cell and double up the internal quotes so VB sees them as
a quote character instead of a String delimiter, it should work. Here is
an example...

Range("A1").Formula="=IF(E7281=""<0.005"",0.0025,I F(F72810,F7281,E7281))"

Notice that I have used 2 quote marks where there will be 1 quote mark
showing in the formula itself.

--
Rick (MVP - Excel)


"YouWontSpamThisAdress" wrote
in message ...
Hi,

I'm trying to put a formula in a cell with my VBA function. The
resulting formula doesn't work, it gives me #NAME? error.

A working formula:

=IF(E7281="<0.005",0.0025,IF(F72810,F7281,E7281))

One put from my VBA function :

=IF(E7292="<0.005",0.0025,IF(F72920,F7292,E7292))

If I simply double-click on the error cell, without editing anything,
the formula works after.

Thanks.