I am trying to write code to insert a formula into a cell and keep getting a "Run-time error '1004'" message when I run the code. Below is the formula that doesn't work.
ActiveCell.Formula = "=IF(AND(SUM(" & ActiveCell.Offset(-1, 0).Address(True, False) & ":" & "$" & Last_Column & "$" & ActiveCell.Offset(-1, 0).Row & ")=0, COUNTIF(" & ActiveCell.Offset(0, -1).Address & ":" & ActiveCell.Offset(0, -1).Address(False, False) & ",""<>0"")<12),SUMIF(" & SRange & "," & """PF_MT_COST""" & "&" & ActiveCell.Offset(0, -6).Address & "," & TRange & ")*Entry!$D$39),0)"
If I change the "Then" statement to ""X"" it works correctly (see below). I think I am missing a double quote some where in the "SUMIF" statement. PLEASE HELP!
This one works:
ActiveCell.Formula = "=IF(AND(SUM(" & ActiveCell.Offset(-1, 0).Address(True, False) & ":" & "$" & Last_Column & "$" & ActiveCell.Offset(-1, 0).Row & ")=0, COUNTIF(" & ActiveCell.Offset(0, -1).Address & ":" & ActiveCell.Offset(0, -1).Address(False, False) & ",""<>0"")<12),""X"",0)"