Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-07-2014, 01:40 AM
NobodysPerfect NobodysPerfect is offline Sorting algorithm for two dimensional array Windows 7 64bit Sorting algorithm for two dimensional array Office 2010 32bit
Competent Performer
Sorting algorithm for two dimensional array
 
Join Date: Jan 2014
Location: Germany
Posts: 136
NobodysPerfect is on a distinguished road
Default Sorting algorithm for two dimensional array

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
But I did not succeed in adjusting it to sorting a two dimensional array.

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting algorithm for two dimensional array 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
Sorting algorithm for two dimensional array 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:55 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft