Why not start by recording a macro that captures the steps of sorting the the data from left-to-right?
Select the data > Menu > Data > Sort: options > sort left to right

From here, it is just a matter of tweaking the code to make it more efficient.