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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,215,746
Messages
6,126,647
Members
449,325
Latest member
Hardey6ix

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
Back
Top