Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Excel formula doesn't work when put in from VBA, but works when written in Excel

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank_T_L - 07 Oct 2007 11:55 GMT
I have made vba-code that makes a formula to be pasted into one cell at the
time in Excel.

The vba-code:
vAktivCelle = "J" & i
       vFormel = "=if(E" & i & "=0;if(((G" & i & "+H" & i &
")*Parametre!$E$5"
       vFormel = vFormel & "+G" & i & "+H" & i & "+I" & i & ")-F" & i &
"<0;0;"
       vFormel = vFormel & "(G" & i & "+H" & i & ")*Parametre!$E$5+G" & i &
"+H" & i & "+I" & i & "-F" & i & ");"
       vFormel = vFormel & "if(G" & i & "+H" & i & "+I" & i & "-F" & i &
"<0;0;"
       vFormel = vFormel & "if(E" & i & "=F" & i & ";0;G" & i & "+H" & i &
"+I" & i & "-F" & i & ")))"
       ActiveSheet.Range(vAktivCelle).Formula = vFormel

This generates this formula:
=if(E2=0;if(((G2+H2)*Parametre!$E$5+G2+H2+I2)-F2<0;0;(G2+H2)*Parametre!$E$5+G2+H2+I2-F2);if(G2+H2+I2-F2<0;0;if(E2=F2;0;G2+H2+I2-F2)))

When I run it - I get this error-message:
Run-time error '1004'
Application-defined or object-defines error

**************

But: if I remove the first "=", and vba just puts the text into the cells -
I can just go to the cell, write "=" in front of the text - and then IT
WORKS....!

Anyone got an idea about why it doesn't work when I put it in from vba?

Frank
Dave Peterson - 07 Oct 2007 12:03 GMT
Excel is USA centric.  

Try changing your semicolons (;) to commas (,).

> I have made vba-code that makes a formula to be pasted into one cell at the
> time in Excel.
[quoted text clipped - 29 lines]
>
> Frank

Signature

Dave Peterson

Niek Otten - 07 Oct 2007 14:10 GMT
You can also look at the FormulaLocal option; it uses local separators and function names

Signature

Kind regards,

Niek Otten
Microsoft MVP - Excel

| Excel is USA centric.
|
[quoted text clipped - 18 lines]
| >
| > This generates this formula:

=if(E2=0;if(((G2+H2)*Parametre!$E$5+G2+H2+I2)-F2<0;0;(G2+H2)*Parametre!$E$5+G2+H2+I2-F2);if(G2+H2+I2-F2<0;0;if(E2=F2;0;G2+H2+I2-F2)))

| > When I run it - I get this error-message:
| > Run-time error '1004'
[quoted text clipped - 9 lines]
| >
| > Frank

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.