+ Reply to Thread
Results 1 to 6 of 6

vba to sort columns according to dates in header from oldest to newest.

  1. #1
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    vba to sort columns according to dates in header from oldest to newest.

    Hi guys, can anyone help me build a code that would resort the entire columns in attached workbook according to the header which are in date format, from oldest to newest.

    reorderdatesoldtonew.xlsx

    Thanks in advance.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: vba to sort columns according to dates in header from oldest to newest.

    Hi rocksan,

    I did a copy and paste using the Transpose. Then sorted by Column A (oldest to newest). Then copied and pasted Transpose a second time to get your answer.
    See attached. Is this what you wanted?
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: vba to sort columns according to dates in header from oldest to newest.

    Hi Marvin,

    I look at the attached and yes, I need it exactly to be like that but the process in VBA code also I cant have any additional data on the page after the process is done, because my other code is going to copy entire columns based on the dates. So just a clean reordering of the columns.

    Thanks.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: vba to sort columns according to dates in header from oldest to newest.

    Hi rocksan,

    Your question is a little vague if you want VBA code. Will there always be that exact number of rows and columns on your sheet or does it vary? Will there be more rows or columns? When we write VBA we need to see what things might change. So, you need to tell us what might move or grow or shrink. Will this data always start on A1? Will there be formulas in the data? All these things are important for writing successful VBA code.

  5. #5
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: vba to sort columns according to dates in header from oldest to newest.

    Marvin,

    Sorry about that.

    Usually i just take the codes answered here and customize it to my needs. Just ask here to get the basic idea.

    To answer your question, The number of rows rows and columns do change, but they are always in reverse format coming from the source, which is uneditable at my side. So yes it is dynamic.

    Fortunately, The data is already modified by my macro to always start in A1, and I only copy values and number formatting. No formulas copied.

    Hope that helps.

    Thanks.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: vba to sort columns according to dates in header from oldest to newest.

    OK rocksan,

    Here is your code that will do what I think you want. See it in the attached.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-05-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: vba to sort columns according to dates in header from oldest to newest.

    Marvin,

    I tried your code, it works perfectly.

    Thank very much for your time and patience Marvin.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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