Excel formula doesn't work when put in from vba, but the formula works in Excel

F

Frank_T_L

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).Value = 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
 
G

George Nicholson

Don't use Value when entering a Formula:
ActiveSheet.Range(vAktivCelle).Formula = vFormel

HTH,
 
G

George Nicholson

Don't use Value when entering a Formula (english version):
ActiveSheet.Range(vAktivCelle).Formula = vFormel


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top