Empty cells should not cause an error unless ALL of the cells are empty.

You'll get the #DIV/0! error if the COUNTIF = 0.

You could get an incorrect result if cells in column D are empty but the corresponding cells in column C contain one of the criteria months.

Which column has the empty cells?