What is your original file?
  • Excel
  • Text with semicolumns

If it is Excel, I would try to recurse the D column from the last cell up to the top (or the first cell with a manager name) and gather all the manager names in an array.
If it is Semicolumn separated text, I would look to the code Richard provided.