Vba formula entry problem

VHS01

Board Regular
Joined
Nov 3, 2005
Messages
139
=COUNTIF(C9:C39,"<.43") entered into a cell works fine
I need to have code enter the formula

Trying to add it programically like this:
Range("C40").Formula = "=COUNTIF(C9:C39,"<.43")"
Gives the following red colored entry error
Compile error
Expected: end of statement

Changing to this:
Range("C40").Formula = "=COUNTIF(C9:C39,<.43)"
Gets rid of the entry error, but gives the following error when it runs
Run-time error ‘1004’:
Application-defined or object-defined error

Please help!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The best way to find out the syntax is to record a macro while doing it manually. This is what I got:

Code:
ActiveCell.FormulaR1C1 = "=COUNTIF(R[-31]C:R[-1]C,""<.43"")"

The recorder uses the FormulaR1C1 property, but the important thing to note is the doubling up of the quotes around the criteria. So using the Formula property it would be:

Code:
Range("C40").Formula = "=COUNTIF(C9:C39,""<.43"")"
 
Upvote 0

Forum statistics

Threads
1,224,271
Messages
6,177,605
Members
452,784
Latest member
talippo

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