Tried for the D column:
#=IF(E5 <= 0, LOOKUP(2,1/($D$4:$D$33<>0),$D$4:$D$33), E5)#
I got this answer from this website but I'm unable to make it work properly. The sum in I4 doesn't calculate properly, either.
More details of issue in image:
Thanks for all your help!
#=IF(E5 <= 0, LOOKUP(2,1/($D$4:$D$33<>0),$D$4:$D$33), E5)#
I got this answer from this website but I'm unable to make it work properly. The sum in I4 doesn't calculate properly, either.
More details of issue in image:

Thanks for all your help!