Took less time than I thought it would, since I stumbled across a much simpler way than whatever over-complicated mess I was trying out.
It's not 100% complete yet - it has to be able to find a way to get them ranking up behind the order position, rather than them ranking up with the top-left guy where you click, and the rest following out. For example, if you were to select a group of 9 and right-click directly below them, it should use the guy whose formation position is (2,3) and use him as the origin for the order.