![]() |
|
#1
|
|||
|
|||
|
Hi to all of you!
My problem today: some sorting algorithm for a two dimensional array. The array consists of (position in text, name of respective bookmark). I want to sort the bookmarks according to their position in the text (first field of array). If possible I use you the "WordBasic.SortArray" to quick sort arrays. But WordBasic.SortArray fails for sorting numbers. So I googled, and googled, and googled … and found a sorting algorithm which works fine for short single dimensional arrays. Code:
Sub BubbleSort(list())
Dim First As Integer, Last As Long
Dim i As Long, j As Long
Dim Temp As Long
First = LBound(list)
Last = UBound(list)
For i = First To Last - 1
For j = i + 1 To Last
If list(i) > list(j) Then
Temp = list(j)
list(j) = list(i)
list(i) = Temp
End If
Next j
Next i
End Sub
The other solution is here: http://www.cpearson.com/Excel/SortingArrays.aspx, but this code is (seems to be) a bit OTT for my purpose. I considered writing the array to a table, sort, and back to array, but that’s not my favored solution for Word. As a workaround I use two arrays: Array1=the positions, Array2=position and name. After sorting Array1 with BubbleSort, I 'join' the two arrays and the result is a bookmark array sorted by position. Purpose: use shortcuts to toggle between any number of next - previous bookmarks. In the end it works, but sorting a two dimensional array still remains an issue and I would appreciate any help. Thanks NP Last edited by NobodysPerfect; 04-07-2014 at 04:01 AM. |
|
#2
|
|||
|
|||
|
Managed to change the "BubbleSort algorithm" to sort my short two dimensional array.
THX anyway NP |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Sorting Challenge
|
gbaker | Excel Programming | 11 | 06-22-2012 09:39 AM |
| Sorting by certain criteria | randenius | Excel | 2 | 06-11-2012 02:18 AM |
Need help in aplhabetica sorting
|
brooklyn86 | Word VBA | 1 | 06-05-2012 11:43 AM |
| Formula for algorithm | santiago_dl | Excel | 0 | 01-11-2012 11:09 AM |
| Sorting elements in a row | Riccardo | Excel | 2 | 12-14-2010 10:08 AM |