+ Reply to Thread
Results 1 to 7 of 7

Macro to Order Numerically Then Alphabetically

  1. #1
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Macro to Order Numerically Then Alphabetically

    Hi,

    I am trying to write a macro to order a spreadsheet of data.
    I wish to create a macro to order each column in alphabetical order from columns G to column BD.

    So far I have the following:

    Sub Sort

    Range("G6:G1000").Sort _
    Key1:=Range("G1"), Header:=xlYes

    Range("H6:G1000").Sort _
    Key1:=Range("H1"), Header:=xlYes

    End Sub



    With this I have 2 problems:
    1) If a cell begins with a letter the macro just removes it. I would like to order each column first by numbers and then by letters, for example:
    0
    1
    2
    5
    9
    A
    C
    F
    Z

    2) I dont fancy copying and pasting the formula over 100 times, I am sure there is an easier way to write this.

    Best Regards,

    Smuntl

  2. #2
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Macro to Order Numerically Then Alphabetically

    The natural sort order IS #s first, then letters. How is a regular sort not doing this?
    did you record the macro , then sort?

  3. #3
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to Order Numerically Then Alphabetically

    You are correct.
    It does that when i create a 'test sheet' for the macro, but for some reason in my data sheet it removes the cells with letters.

  4. #4
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Macro to Order Numerically Then Alphabetically

    Quote Originally Posted by smuntl View Post
    You are correct.
    It does that when i create a 'test sheet' for the macro, but for some reason in my data sheet it removes the cells with letters.
    Hi Smuntl;

    I believe the first problem is the range that you've identified. The macro isn't necessarily "removing" the data, it's just sorting the Null value higher than some values rather than others.

    If you begin your macro with:
    Please Login or Register  to view this content.
    And then adjust your macro to read something like:
    Please Login or Register  to view this content.
    That may fix the 'deletions'.

    Even if it doesn't really fix anything, it'll curb the scope of the macro down to make it run faster, and help us get to a better solution.
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  5. #5
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to Order Numerically Then Alphabetically

    Thanks,

    I realised that the letters are going right to the bottom of the spreadsheet. Will try the changes you mention and also look for something to remove those blank cells.

    Thanks

  6. #6
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Macro to Order Numerically Then Alphabetically

    Quote Originally Posted by smuntl View Post
    Thanks,

    I realised that the letters are going right to the bottom of the spreadsheet. Will try the changes you mention and also look for something to remove those blank cells.

    Thanks
    The little clause provided just curbs the scope of the macro. The Blank Cells are a biproduct of selecting too much. If you only are trying to sort 3 values, but are selecting 10 cells, it'll sort those 3 within the 10. However, using something like:
    Please Login or Register  to view this content.
    Will select the LAST value in the column, therefore reducing the scope from a hard-coded 10, to a variable 3.

  7. #7
    Registered User
    Join Date
    05-11-2014
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Macro to Order Numerically Then Alphabetically

    Hmm,

    Now I am confused.
    Even if I reduce the area then it is still putting the letters right at the bottom.

+ 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: 7
    Last Post: 07-02-2012, 07:23 PM
  2. RANK numerically and then alphabetically
    By liam-the-1-n-only in forum Excel General
    Replies: 7
    Last Post: 05-12-2010, 10:30 AM
  3. sort alphabetically and numerically, then sort rows
    By luke20allen in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-01-2008, 07:00 AM
  4. I need to sort alphabetically and then numerically
    By luke20allen in forum Excel General
    Replies: 3
    Last Post: 09-18-2008, 10:22 PM
  5. Replies: 1
    Last Post: 01-17-2007, 06:43 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