Hi,
I'm having difficulty with a macro. I'm trying to re-order the columns in a tab based on a specified order. For example the top row has "x" in column A (cell a1), z in column B (cell b1), y in column C (cell c1), w in column D (cell d1). Could you please help me figure out the macro required to re-arrange the entire columns so that the order of the top row was "w,x,y,z"?
I've attached the worksheet which shows the original state.
Last edited by 2seas; 01-05-2012 at 09:13 AM. Reason: Solved
Sub ert() With [a1].CurrentRegion 'on active sheet .Sort Key1:=.Cells(1), Order1:=xlAscending, Orientation:=xlLeftToRight End With End Sub
thankyou very much for the reply. i guess i gave a bad example as the ordering i need isn't alphabetical. the actual column headers (which i can't share for security reasons) are made of text but need to be ordered in a particular way. so giving another example, let's say the column headers were names: James, Andy, Karen. How can I write a macro to sort the entire columns so that the names in the top row would be in the order Karen, Andy, James?
the principle rule is to be able to sort entire columns according to a specified order of the top row. so if i specified the order for the top row (say for example in a list somewhere) the macro should work in such a way as to re-sort the columns so that at the end the top row aligns to the initial specification. does that help clear up the requirement?
For example. Try to change the order of words in green cells (H1:H4), and click the green arrow.
this is great! thank you very much.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks