EXCEL - how to change the sequence of specific columns

Is it possible to have EXCEL to change the sequence order of attributes automatically.  Use Case - user has 100 columns in spreadsheet and a certain section of these needs to be reordered.    Let's say a spreadsheet has the column headers listed below.

           ID    Name   Date  Description  Size Length Height

How can EXCEL automatically re-arrange the Size, Length and Height so it looks like this:

           ID    Name   Date  Description  Height Size Length

This work cannot be done manually because in reality there are about 25 column headers that need to be re-arranged daily.   I was hoping someone can point me to a solution that allow the users to define the columns that need to re-arranged and define the order they need to be displayed in without impacting the other columns in the file.  I attached another example;
Sample.xlsx
tmajor99Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russell FoxDatabase DeveloperCommented:
It's only possible via a macro or VBA. If you record a macro while you do the appropriate actions once, Excel will automatically generate the VBA code and allow you to save the macro for later use. The next time you open up a new spreadsheet with the columns out of order, just run the macro.

Note that it gets a little more complicated if someone else needs to use the macro: Excel likes to disable macros written by someone else so hackers can't use them. Just let the user know that it's safe and they can bypass the security message. Alternatively, you can get a personal security certificate and they can "trust" that certificate, allowing any VBA you're written to be auto-trusted.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Saurabh Singh TeotiaCommented:
You can run this code which will do what you are looking for..

Sub movecolum()
    Columns("C:C").Cut
    Columns("A:A").Insert Shift:=xlToRight
    Columns("C:C").Cut
    Columns("B:B").Insert Shift:=xlToRight
    Columns("F:F").Cut
    Columns("D:D").Insert Shift:=xlToRight
  End Sub

Open in new window


Saurabh...
Martin LissOlder than dirtCommented:
Here is a workbook that I think works very well.

To use it the user goes to the "Col Sequence Number" sheet and enters numbers in row 2 that indicate where that particular column should be placed. Columns without a number are left in the same place as they are now.  Note that when the user activates the "Col Sequence Number" sheet the header is copied from the "Current format sheet". Also note that it doesn't matter how many columns there are. He/she then clicks the "Reorder Columns" button and presto!
28836839.xlsm
Martin LissOlder than dirtCommented:
Added some validations to my previous attachment and corrected a bug.
28836839a.xlsm
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.

Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.