+ Reply to Thread
Results 1 to 9 of 9

Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

  1. #1
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Please Login or Register  to view this content.
    MERRY CHRISTMAS TO EVERYONE AND SEASONS GREETINGS...

    Dear Forum,

    I am already working on a code to Re-Arrange the Column Order from a RAW DATA extracted from a Business Intelligence BI Tool which has excess columns and not all columns are relevant to my work so I need to not only RE-ORDER or ARRANGE their ORDER but also DELETE the remaining COLUMNS which are irrelevant to me.

    I have three Sheets in the Sample File, one is the RAW DATA which has 26 Columns - with the Column Headers such as COL A, COL B ,.... till COL Z in the Sheet - Original Column Order , then in the other Sheet - Ordering Sheet - I have maintained as List of all the Columns which I need to be Arranged in the Order as mentioned in the Column A, now this Range from ("A2:A10") is of the ORDER of the Columns as well as I need to only keep the Columns which have this name in this order and then delete the remaining Columns.

    I found some code online which I managed to tweak but in vain not got the desired result till now, so some experts can really help me on this..
    I need to keep this RANGE Dynamic Always as in Future I would like to actually build a Macro to actually capture and Transpose all the Column Headers from the Sheet - Original Column Header in the Ordering Sheet..

    Please Login or Register  to view this content.
    Last edited by e4excel; 12-24-2022 at 11:08 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,666

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Simple AdvancedFilter
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Thanks Jindon, It works really well however can you please explain the CODE as I am no expert ...
    Dim x - Is it a Variant ?

    Very Nice Crisp Code but please explain...as I would also be creating the Ordering Sheet using a Macro from the Original Sheet like Copy all the Column Headers from the Original Column Order Sheet and then Transpose and then Maybe add a Yes / No or the Numbers 1,2,3 to decide the ORDER of the Columns in the adjacent Column to decide which Columns to Keep in the Final Order Col Sheet.

    SO I was thinking of using an Array to store the Column Headers and then pass the same to be SORTED and REMOVED accordingly...

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,666

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Quote Originally Posted by e4excel View Post
    Dim x - Is it a Variant ?
    Any variables declared without data type are Variant in VBA.
    Quote Originally Posted by e4excel View Post
    Very Nice Crisp Code but please explain...as I would also be creating the Ordering Sheet using a Macro from the Original Sheet like Copy all the Column Headers from the Original Column Order Sheet and then Transpose and then Maybe add a Yes / No or the Numbers 1,2,3 to decide the ORDER of the Columns in the adjacent Column to decide which Columns to Keep in the Final Order Col Sheet.
    Explain what?
    Quote Originally Posted by e4excel View Post
    SO I was thinking of using an Array to store the Column Headers and then pass the same to be SORTED and REMOVED accordingly...
    I think you are on the right track, so go for it.

  5. #5
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Quote Originally Posted by jindon View Post
    Simple AdvancedFilter
    Please Login or Register  to view this content.
    THanks in advance

  6. #6
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Dear Forum,

    With my Original Code, can someone please explain as to where was I going wrong ? I actually wanted to pass a Range to the Array so that it would always be more Dynamic , but somewhere Im missing something...
    SO can someone also please help me also Modify My COde so that this becomes a good learning..

    The Solution from Jindon is great but since I too had started I would also like to build the code already started so please can someone help me on this..

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Dear Forum,

    Can someone please help me with my approach too..

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA


    Hello,

    as your approach is very not the way to go, useless & overcomplicated,
    if I have answered before jindon I should post the same Excel basics advanced filter way …

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,505

    Re: Re-Order Cols and Delete Cols when a List of Col Names in Order is Given using VBA

    Just for the fun of it...Here is another Option...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 10-07-2016, 01:40 PM
  2. [SOLVED] Sum columns (duplicates in row header) & delete duplicate cols to leave single unique cols
    By kinrossfarm in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-20-2014, 05:50 AM
  3. Replies: 9
    Last Post: 11-17-2011, 12:58 PM
  4. Range.Select 1st pass 13 cols, 2nd paqss 25 cols twice as wide in error?
    By Craigm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2006, 06:04 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1