+ Reply to Thread
Results 1 to 8 of 8

How to sort a 2-d vector alphabetically in VB

  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    How to sort a 2-d vector alphabetically in VB

    If I have a 2-d vector similar to below, how do I sort it alphabetically (A-Z) in VB using column 2? Is there an "Application.Sort()" command I can use or something similarly simple?

    1 AS
    2 QW
    4 DF
    6 DE
    3 GR
    4 LE
    5 PW

    Thanks
    You either quit or become really good at it. There are no other choices.

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: How to sort a 2-d vector alphabetically in VB

    Assuming your data set is stored in Column A and B, your sort statement will looks similar to this
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: How to sort a 2-d vector alphabetically in VB

    Ok, thanks. Actually it's a 2-D vector generated by VB and never stored in a spreadsheet.

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: How to sort a 2-d vector alphabetically in VB

    Oh. Haha, then you maybe you can try to store the list into a multi dimension array and then do a bubble sort.

  5. #5
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: How to sort a 2-d vector alphabetically in VB

    Ok, never heard of a bubble sort. Would you be able to give a code example?

  6. #6
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: How to sort a 2-d vector alphabetically in VB

    Look the reply from Hans Vogelaar

    https://social.msdn.microsoft.com/Fo...n?forum=isvvba

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,888

    Re: How to sort a 2-d vector alphabetically in VB

    Bubble sort is one of the least efficient, but a very simple algorithm. List of sorting algorithms, and Wikipedia often includes code or pseudocode examples: https://en.wikipedia.org/wiki/Sorting_algorithm

    If you are going for coding your own sorting algorithm, a selection sort might be a better sorting algorithm.

    The easiest approach (if you are allowed) might be to write your VBA array into a spreadsheet, then use Excel's built in sorting algorithms. Using JieJenn's original proposal:
    Please Login or Register  to view this content.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  8. #8
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: How to sort a 2-d vector alphabetically in VB

    Ok, thanks, guys. Looks like I'll have to do bubble sort - outputting it to spreadsheet is not an option at this point.

+ 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. How to sort Alphabetically
    By sunblue in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-24-2015, 06:09 AM
  2. Sort Alphabetically
    By Bob@Sun in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-23-2015, 10:18 AM
  3. Sort Alphabetically each 6th row
    By Jonathan78 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2013, 03:15 PM
  4. [SOLVED] Sort Array Alphabetically
    By gsurge in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-04-2012, 12:03 PM
  5. How to sort a listbox alphabetically?...
    By 10121730 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2012, 03:03 AM
  6. 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
  7. sort by alphabetically
    By HOW CAN I SORT BY ALPHABETICALLY FROM A in forum Excel - New Users/Basics
    Replies: 4
    Last Post: 05-12-2005, 01:06 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