+ Reply to Thread
Results 1 to 6 of 6

Use sort method to sort ranges based on their headings using vba

  1. #1
    Registered User
    Join Date
    01-02-2013
    Location
    Kristiansand, Norway
    MS-Off Ver
    Excel 2010
    Posts
    6

    Use sort method to sort ranges based on their headings using vba

    Hi..

    I have several ranges in column B to D, and the heading of each range is in column A.
    How can I sort the ranges based on their heading using vba?
    The headings are text that i'd like to sort alphabetically..and i need the numbers under each heading needs to stay as they are.

    I attached an example showing what my original document looks like..

    Thank you in advance, Kris
    Attached Files Attached Files

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Use sort method to sort ranges based on their headings using vba

    kris,

    the only way I can think of is:
    step 1: copy the header value to the applicable "number rows" belonging to that header (so basically fill A2 to A6 with value "AB", and repeat this for headers "KL" and "CD")
    step 2: sort the entire range on column A only
    step 3: remove the values in column A for those rows where the cell in column B is not blank
    If you like my contribution click the star icon!

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Use sort method to sort ranges based on their headings using vba

    Kris,

    In VBA this would look like

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-02-2013
    Location
    Kristiansand, Norway
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Use sort method to sort ranges based on their headings using vba

    Thank you Ollie!

    That might be a good way of solving my problem.
    I will test this as soon as I can to see if it works..

  5. #5
    Registered User
    Join Date
    01-02-2013
    Location
    Kristiansand, Norway
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Use sort method to sort ranges based on their headings using vba

    The code works perfect, but there's still one thing:
    How do I move the whole row with the sort method in the bottom of your code?
    Cause I have more info in other columns that should follow the "A"-cell

  6. #6
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Use sort method to sort ranges based on their headings using vba

    Sorry, but i do not understand your question. Can you please rephrase?

+ 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