Formula to generate corrected numbers for sorting:
Code:
=IF(A2="D",90000000000+ROW(),COUNTIF($A$2:$A$14,"<="&A2))
Assuming previous formula is in col B, formula to generate the sorted list would be:
=INDEX($A$2:$A$14,MATCH(SMALL($B$2:$B$14,ROW(A1)),$B$2:$B$14,0))