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
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.
Assuming your data set is stored in Column A and B, your sort statement will looks similar to thisPlease Login or Register to view this content.
Ok, thanks. Actually it's a 2-D vector generated by VB and never stored in a spreadsheet.
Oh. Haha, then you maybe you can try to store the list into a multi dimension array and then do a bubble sort.
Ok, never heard of a bubble sort. Would you be able to give a code example?
Look the reply from Hans Vogelaar
https://social.msdn.microsoft.com/Fo...n?forum=isvvba
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.
Originally Posted by shg
Ok, thanks, guys. Looks like I'll have to do bubble sort - outputting it to spreadsheet is not an option at this point.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks