Try this array formula in E6 then drag down:

=IF(D6="F",ROW()-MAX(IF($D$5:D6<>"F",ROW($D$5:D6))),"")

...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.