Inserting countifs to the last row

NocoffeeNoWorkee

New Member
Joined
Apr 28, 2016
Messages
12
I would like to enter a countifs formula into the last row of Col A and have it be able to apply to any columns if it were copy&pasted.

Criteria: Count everything in between the dates in Cells A1 and A2.
Criteria Range: Everything from Cell A3 to the last Row or one above the countifs function.

I tried using code to enter the formula as a string:

Sub Countifs4()
Worksheets("MVT_TREND").Range("A" & Rows.Count).End(xlUp).Offset(1).Formula = "=COUNTIFS(A3:Range(""A"" & Rows.Count.End(xlUp)),"">=""&A1,A3:Range(""A"" & Rows.Count.End(xlUp)),""<""&A2)"

End Sub

<tbody>
</tbody>



but it gives a #NAME? error in the correct cell. I think it has something to do with the "A & last row" part.
Any ideas?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try

Code:
Worksheets("MVT_TREND").Range("A" & Rows.Count).End(xlUp).Offset(1).Formula = "=COUNTIFS(A3:" & Range("A" & Rows.Count).End(xlUp).Address(0, 0) & ","">=""&A1,A3:" & Range("A" & Rows.Count).End(xlUp).Address(0, 0) & ",""<""&A2)"
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,591
Members
449,174
Latest member
chandan4057

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