+ Reply to Thread
Results 1 to 9 of 9

VBA to sort columns left to right - oldest to newest

  1. #1
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    VBA to sort columns left to right - oldest to newest

    Hi,

    I'm trying to sort some data i have loaded into my templates, following my copy paste code i would like to add some more code to sort the data left to right and oldest to newest.

    Any ideas on how to do this;

    The sheet name is IPD and the range i want to sort is D:AA

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA to sort columns left to right - oldest to newest

    You can use excels built in sort for this...
    using the macro recorder gives something like:
    Please Login or Register  to view this content.
    so you probably need something like:
    Please Login or Register  to view this content.
    assuming row 1 contains your dates you want to sort by or something like that.

  3. #3
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to sort columns left to right - oldest to newest

    Thanks i've added this to my code as follows;

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA to sort columns left to right - oldest to newest

    small comment, the with loop doesn't do anything, you need:
    Please Login or Register  to view this content.
    for the with sheets("IDP") to apply to the range.

  5. #5
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to sort columns left to right - oldest to newest

    Thanks, i've changed that and it brings an error;

    'Sort method of range class failed'

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA to sort columns left to right - oldest to newest

    Can you upload an example workbook please?

  7. #7
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to sort columns left to right - oldest to newest

    Here's a sample, workbbok is a lot bigger but trimmed down to fit upload limit.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: VBA to sort columns left to right - oldest to newest

    The sheet in your workbook is "IPD" but the sheetnamen in your code is "IDP"...

    If I change it to:
    Please Login or Register  to view this content.
    It works for me

  9. #9
    Forum Contributor
    Join Date
    05-01-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    822

    Re: VBA to sort columns left to right - oldest to newest

    Many thanks

+ 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. [SOLVED] Dates seem formatted correctly, but will not sort newest to oldest.
    By MelindaCapri in forum Excel General
    Replies: 6
    Last Post: 02-11-2015, 02:34 PM
  2. [SOLVED] vba to sort columns according to dates in header from oldest to newest.
    By rocksan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-25-2012, 12:57 AM
  3. sorting a selected range by date, oldest to newest
    By zed commander in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2012, 12:40 PM
  4. Top ten oldest and top ten newest
    By jhiltabidel in forum Excel General
    Replies: 11
    Last Post: 07-08-2011, 04:59 PM
  5. oldest to newest
    By Hidai in forum Excel General
    Replies: 5
    Last Post: 01-10-2011, 12:14 PM

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