'"Object required" error when using COUNTIFS in VBA

I've got the following line of code

 Worksheets("Pie_Chart").Range(countif_location) = WorksheetFuntion.CountIfs(Range(range_search_countif), failure_to_compare, Range(range_date), ">=" & CDbl(CDate(start_date)), Range(range_date), "<=" & CDbl(CDate(end_date)))

and these are the values of my variables.

countif_location = "D42"

range_search_countif = "Z2:Z39"

range_date = "E2:E39"

start_date = "21/02/2022"

end_date = "28/02/2022"

I don't know why but when I try to run this I get the following error "Run-time error '424'; Object required"

Does anybody know why this is happening?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source