Try this:
=IF($B5>$D$1,IF((AND($B5>=J$4,$B5<K$4)),$C5,0),IF(AND($D$1>=J$4,$D$1<K$4),$C5,0)) (formula in j5)