Dim xRange as Range
Set xRange=Cells(Rows.Count,4).End(xlup)
Set xRange=Range(Range("d12"),xRange)
answer=Application.CountIf(xRange,"apple")
Sub test()
Dim x As Long
x = Range("D" & Rows.Count).End(xlUp).Row
If x < 12 Then x = 12
Range("D6") = Application.WorksheetFunction.CountIf(Range("D12:D" & x), "apple")
End Sub