Code:
Sub RearrangeColumns()
'http://www.excelfox.com/forum/f22/swapping-rearranging-multiple-columns-data-493/
'in the code as expressed below, column C moves to first position, B stays in second, E is thrd, etc.
'Const NewOrder As String = "C,B,E,F,H,AC,K,AF,T,M,S,G,X,I,Z,AA,L,AG,AE,AH,AD,AI,A,D,J,N,O,P,Q,R,U,V,W,Y,AB,AJ"
Dim X As Long, LastRow As Long, Letters As Variant
'Type in order of what column you want in what position
'Make sure there are no spaces in this string
Const NewOrder As String = "D,E,AC,AD,AE,AB,B,C,F,G,H,I,J,K,L,M,N,P,X,Y,Q,R,S,T,U,V,W,A,AA,O,Z"
LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
Letters = Split(NewOrder, ",")
For X = 0 To UBound(Letters)
Letters(X) = Columns(Letters(X)).Column
Next
Range("A1").Resize(LastRow, UBound(Letters)) = Application.Index(Cells, Evaluate("ROW(1:" & LastRow & ")"), Letters)
End Sub
Bookmarks