+ Reply to Thread
Results 1 to 14 of 14

Sorting alphanumerical column in numeric order

  1. #1
    Registered User
    Join Date
    08-12-2004
    Location
    Mendoza, Argentina
    MS-Off Ver
    Office Professional 2003
    Posts
    89

    Sorting alphanumerical column in numeric order

    It's me again - sorry to trouble you but I can't solve this.

    Column H has a text only (address) - Primary sort column
    Column G has text and numbers, sometimes only numbers - secondary sort column
    Column B has text only

    I need a macro to sort the 3 columns with column G in numerical order.

    Example:
    Col B Col G Col H
    Jones house 12 in Main Street, Town
    Smith 24 Main Street, Town
    Mills 63a Ring Road, Town

    Obviously, Col H has to be the primary sort column so that all the same street names are kept together. This is OK on the normal sort option. However, col G is required in numerical order so that the result will be 1 to (say) 88 Main Street, Town.

    I am so befuddled with this that I can't even pretend to have some sort of code.

    Thanks for any help.
    Last edited by thadacto; 03-22-2017 at 04:32 PM.

  2. #2
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Sorting alphanumerical column in numeric order

    Why don't you add a column and put the house number in that column? That would make the job much easier.

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

    Re: Sorting alphanumerical column in numeric order

    I too am confused, as I didn't see you had posted before. Sorry.

    Now - if you could attach a sample workbook I could look at your problem and most likely give you a good answer.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sorting alphanumerical column in numeric order

    Hi thadacto, I've written a quick-n-dirty routine to find the first numeral for each entry in Column G of Range B2:H11. It chops off preceding characters and parks the result in Column I for you to use as your secondary sortfield. It's VERY basic, but perhaps you can refine it. Good luck.
    Please Login or Register  to view this content.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Sorting alphanumerical column in numeric order

    Quote Originally Posted by Raphaelp View Post
    Why don't you add a column and put the house number in that column? That would make the job much easier.
    This would probably be my approach, as well
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  6. #6
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sorting alphanumerical column in numeric order

    I'm back. Here's a better version of yesterday's code which implemented the "extra column" approach as per Raphaelp. (and others). It's a more thorough approach, and more easily adapted to your worksheet. Hope it helps.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    08-12-2004
    Location
    Mendoza, Argentina
    MS-Off Ver
    Office Professional 2003
    Posts
    89

    Re: Sorting alphanumerical column in numeric order

    Quote Originally Posted by MarvinP View Post
    I too am confused, as I didn't see you had posted before. Sorry.

    Now - if you could attach a sample workbook I could look at your problem and most likely give you a good answer.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Hi Marvin, thanks for joining this post. Attached is a sample of what I have in my workbook (sheet1). In the sample sheet 1 is similar to what I have and sheet 2 is what I need out of the code/ A few more pieces of info on the sheets.

    You will find some further info on the worksheets - Sheet 1 is what may be found in my data while sheet 2 is what I hope to have when sorted - each number in numerical order i.e. 1 before 10, and and 2 before 20, etc.

    I don't see the attachment, so I'll have another go at that.
    Attached Files Attached Files
    Last edited by thadacto; 03-23-2017 at 07:50 PM.

  8. #8
    Registered User
    Join Date
    08-12-2004
    Location
    Mendoza, Argentina
    MS-Off Ver
    Office Professional 2003
    Posts
    89

    Re: Sorting alphanumerical column in numeric order

    Hi teelnich. Many thanks for all the work you must have done i producing that code. Most of it I don't understand as there are a lot of functions (?) used which I have never seen before.

    Your first version worked asfar as producing the extra column I. However when I tried to use the sort code I got an error 438 (I think) - "object doesn't support this property or method". This occurred on the first line of the sort code

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This is the line that gets highlighted when I try to debug.

    I have tried, for many hours and searching on the internet to try and resolve the problem but to no avail.

    Perhaps the uploaded file will help.

    Again, many thanks for all the work you hav eput into this for me. I tried your second offering and that certainly, it looks much neater. Using the excel Sort doesn't give what I need.
    Last edited by thadacto; 03-23-2017 at 07:43 PM.

  9. #9
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Sorting alphanumerical column in numeric order

    My advice to you is as follows:

    Put this in column I:
    Please Login or Register  to view this content.
    and then sort first by column H, then by column I, (then by column B, if you so desire) and click on the popup "Sort anything that looks like a number as a number."

    This should do what you are trying to accomplish.
    Last edited by Raphaelp; 03-24-2017 at 09:54 AM.

  10. #10
    Registered User
    Join Date
    08-12-2004
    Location
    Mendoza, Argentina
    MS-Off Ver
    Office Professional 2003
    Posts
    89

    Re: Sorting alphanumerical column in numeric order

    Thanks for the help, Raphaelp.

    Unfortunately, when I paste that code into I1, I get an error "#NAME?".

  11. #11
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Sorting alphanumerical column in numeric order

    Put this in a Standard module and run Sub tst.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  12. #12
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Sorting alphanumerical column in numeric order

    Hi Thadacto- Try this:
    Please Login or Register  to view this content.
    Make sure you change the Workbook and Worksheet references. Good luck!
    Last edited by leelnich; 03-27-2017 at 07:06 PM. Reason: I said post #11 code was faster. It's NOT, I tested it.

  13. #13
    Registered User
    Join Date
    08-12-2004
    Location
    Mendoza, Argentina
    MS-Off Ver
    Office Professional 2003
    Posts
    89

    Re: Sorting alphanumerical column in numeric order

    Thank you all for your help and codes.

    I used bakerman2's code which worked straight out of the box. And a special thanks to you, bakerman2 for that short piece of code which has solved the problem.

    Again thanks to all who helped.

  14. #14
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Sorting alphanumerical column in numeric order

    You're welcome and thanks for rep+.

+ 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] Copy and paste from random order to alpha-numeric order
    By OthelloDog in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-03-2016, 11:11 PM
  2. Sorting alphanumerical characters sequencially.
    By jlbello in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-22-2016, 05:01 PM
  3. Sorting Alphanumerical values
    By Kreppie in forum Excel General
    Replies: 3
    Last Post: 09-03-2014, 07:49 AM
  4. sorting alpha numeric in one column
    By coasterhhh in forum Excel General
    Replies: 7
    Last Post: 02-13-2014, 05:08 AM
  5. Sorting out variable length alphanumerical data
    By axtryo in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-21-2013, 01:10 AM
  6. Replies: 7
    Last Post: 04-20-2010, 04:28 PM
  7. Sorting Worksheets in numeric order.
    By CParnell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-06-2007, 07:30 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