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:
[TABLE="class: outer_border, width: 750"]
<tbody>[TR]
[TD]
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
[/TD]
[/TR]
</tbody>[/TABLE]



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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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