The usual way to do something like this would be to use INDEX
and SMALL
in an array entered formula:
=IFERROR(INDEX(A:A,SMALL(IF(B:B<>0,ROW(B:B)),ROWS($B$1:B1))),"")
Put that in the first cell in column N and after typing the formula, don't press Enter. Instead, press Ctrl+Shift+Enter
And then you can drag it down.