Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using IF in Excel 97 with VBA 1

Status
Not open for further replies.

beec

Programmer
Apr 3, 2002
13
0
0
GB
I'm trying to insert a formula in my Excel 97 worksheet through a VBA script. I want to insert a formula wich contains the IF statement but I get an error message. How can I solve this ? My code is as follows :


Range(&quot;E2&quot;).Formula = &quot;=IF(AND(D2<0;D1>=0);1;99)&quot;
Range(&quot;F2&quot;).Formula = &quot;=IF(E2=1;C2;F1)&quot;
Range(&quot;G2&quot;).Formula = &quot;=IF(AND(D2>=0;D1<0);C2-F2;99)&quot;
Range(&quot;H2&quot;).Formula = &quot;=D1&quot;

I also tried to do this with a string variable but with the same error.

Bert.
 
That looks fine - as long as your seperator is indeed a ;
If not, you need to replace all ; with ,

I did that and the formulae were entered just fine

Rgds
Geoff
&quot;Some cause happiness wherever they go; others whenever they go.&quot;
-Oscar Wilde
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top