When I try to make a dynamic formula with VBA in excel i get this error message.
This line is just fine:
ActiveCell.Value = "IF(SUM(" & Range("A1:A5").Address & ")*0,1>" & Range("B1").Address & ";" & Range("C1").Address & ";SUM(" & Range("A1:A5").Address & ")*0,1)*-1"
If i add = in front of my IF-statement like this, I get the error.
ActiveCell.Value = "=IF(SUM(" & Range("A1:A5").Address & ")*0,1>" & Range("B1").Address & ";" & Range("C1").Address & ";SUM(" & Range("A1:A5").Address & ")*0,1)*-1"
If i just add the = sign after testing the first code. It runs fine in excel. What am i doing wrong here?
Don't mind the ranges and stuff. They are only placeholders to make the example as similar to my code as possible.
To enter a formula in a cell you have to use the .Formula
property instead of .Value
.
Try this
ActiveCell.Formula = "=IF(SUM(" & Range("A1:A5").Address & ")*0,1>" & Range("B1").Address & ";" & Range("C1").Address & ";SUM(" & Range("A1:A5").Address & ")*0,1)*-1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With