This proposed solution uses two helper columns headed 'Max <' and 'Min >', which may be hidden for aesthetic purposes. The formulas for the two helpers could be incorporated into the formula for column D, but I feel that it is easier to see what they are doing if they are separated.
The array entered formula that populates the 'Max <' column is:
Formula:
=K4-MAX(IF(SMTDates<$K4,SMTDates))
The array entered formula that populates the 'Min >' column is:
Formula:
=ABS(K4-MIN(IF(SMTDates>$K4,SMTDates)))
The array entered formula that populates column D is:
Formula:
=IF(ISBLANK($B4)=FALSE,IF(M4<N4,MAX(IF(SMTDates<$K4,SMTDates)),MIN(IF(SMTDates>$K4,SMTDates))),"")
*Array entered formulas are confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
Let us know if you have any questions.
Bookmarks