Ascending
A1 has to be 0
=IF(D2<>"",MAX($A$1:A1)+1,"")
A B C D
Descending
A1 has to be the highest number plus 1
=IF(D3<>"",MIN($A$1:A2)-1,"")