DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   difficulty creating a formula with a macro (http://www.daniweb.com/forums/thread60875.html)

Carlos Sa Nov 7th, 2006 7:00 pm
difficulty creating a formula with a macro
 
Hello, all


I am having some difficulty in a part of a macro where I want to insert this formula in an Excel spreadsheet.

=IF(TRIM(D12)="REG:",1,0)+IF(E12,1,0)

When executed, one of the problems I am having is that apostrophes are inserted around "E12", so the second IF looks like:
IF('E12',1,0)
and excel marks it with an error...

I bypassed the same error on the TRIM function by writing it like this:
TRIM("D12").

If I try the same method for the IF(E12,1,0) part, I get a syntax error.

This is the actual statement from the VB macro:
ActiveCell.FormulaR1C1 = "=IF(TRIM(""D" & detailrow & """)=""GEO:"",1,0)+IF(E" & detailrow & ",1,0)"
and this is the result:
=IF(TRIM("D12")="GEO:",1,0)+IF('E12',1,0)


Thanks in advance for any suggestions

Carlos


All times are GMT -4. The time now is 11:08 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC