VBA error 1004

ino_mart

Registered User.
Local time
Today, 03:15
Joined
Oct 7, 2009
Messages
78
All

I have an Access-database which creates an Excel file. I have to calculate the TREND, but for some reason next code does not work

oSheet.range(Chr(intChar) & intTeller).formula = "=IF(I" & intTeller & "="""";"""";TREND(I" & intTeller & ":L" & intTeller & ";I$1:L$1;M$1))"

This results in "Run-time error '1004': Application-defined or object-defined error"

If I remove the equal-sign before IF, the code runs. Of course, Excel does not calculate this as it is not a formula due to the missing =

The same error appears when using next lines
oSheet.range(M2).formula = "=TREND(I2:L2;I1:L1;M1)"
oSheet.range(M2).value = "=TREND(I2:L2;I1:L1;M1)"

Changing the ; into , neither solves this issue.

I also tried to record a macro in Excel. This results in code that works:
oSheet.range(Chr(intChar) & intTeller).FormulaR1C1 = "=TREND(RC[-4]:RC[-1],R[-1]C[-4]:R[-1]C[-1],R[-1]C)"
This is howver no solution as it only works for the row I selected.

Anybody an idea how to solve this?

Regards
Ino
 
Last edited:
I found the solution by using
oSheet.range(Chr(intChar) & intTeller).Value = "=if(L" & intTeller & "="""","""",TREND(I" & intTeller & ":L" & intTeller & ",I1:L1,M1))"
 

Users who are viewing this thread

Back
Top Bottom