Cell Formula with VBA code NOT Working

nickh22

New Member
Joined
Nov 22, 2004
Messages
8
:oops:
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! :eek:

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)"
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,136,308
Messages
5,674,993
Members
419,541
Latest member
freddyboots

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top