Frank has a simple two-column table that contains random dates in the first column and the letters A through E in the second column. He formats the cell containing the letter C so it has a background color and a border around the cell. When Frank sorts the table according to what is in the first column, Excel moves the background color with the C cell, but it doesn’t move the border. Frank wonders if there is a way to move both the color and border of a cell when sorting.
The solution is to change how you are doing your formatting. Excel provides two types of formatting that can be applied to cells-regular formatting and conditional formatting. If you apply regular formatting, then what moves when you sort can seem rather arbitrary. If you apply conditional formatting, then all the formatting applied by the condition (or conditions) will move with the cell when you sort.
So the answer to the question is to change how you do your formatting in this instance. Just apply a conditional format that modifies the border of the cell, and then you can sort in peace. (The condition you set could easily be one that is always True, and thus the formatting always applied.)