Kamis, 02 Februari 2012

Re: [ExcelVBA] Re: Sorting

 


Wow!!!!

Left and Right were the original variables so I just left them and prefixed for type... using one of my procs :-)

Nearly all the merge sorts I read used similar "nomenclature" as well as L and R.

One of what I thoughr would be a great routine that also used an Insertion sort when the number of sort items got below 10, I couldn't get to work... so I just "massaged" the code I found... that did work... from the documented URL.
'
I'm so impressed David!!! Thank you for taking the time! I'm going to look at your ammendments tommorow... It's a bit late here just now.

Good point about numeric entries, I tried numbers but admit to generating single digits. I'll look at that again.

Thank you again!!!

Lotsa Hugs... Lisa

-----Original Message-----
From: David Braithwaite <dbraithwaite@charter.net>
To: ExcelVBA <ExcelVBA@yahoogroups.com>
Sent: Thu, Feb 2, 2012 8:47 pm
Subject: [ExcelVBA] Re: Sorting

Yikes!!

This is complicated ... congrats for getting it to work.
I find use of lngpLeft and lngpRight to as cursors for the rows being
ompared, confusing as I think of row numbers being vertical (up/down) and
olumns being horizontal (left/right)
It can be significantly simplified:

Leaving aside how the two entries to be compared are determined, the inner
uts can be done much simpler

Comparing multiple keys (compare on highest priority of remaining keys if
ll higher priority keys are equal)
Following is combination of Meta and code..should be taken as suggestive..

For Col = lbound(ListOfKeyColumns) to
bound(ListofKeyColumns)
Select case
trcomp(theArray(right_row,col),thearray(left_row,col),vbtextcompare)
Case 0: 'this and all prior
eys equal, compare next key
Case > 0 'out of order
assuming ascending)
<Swap the
ows --- see below>
Exit for
Case < 0 'rows in correct
rder (assuming ascending)
Case else
Msgbox "?I
m in the twilight zone.again"
End select
Next col

A smaller simplification: Swapping entry values, you can do it in one loop

SwapRow:
For Col = lbound(theArray,2) to
bound(theArray,2) 'assuming array is dimensioned as (Rows,Columns)
theTemp =
heArray(right_row, col)
theArray(right_row,col) =
heArray(left_row,col)
theArray(left_row,col) =
heTemp
next col

Note that, as you have it, this will treat numeric values as strings and
1234" will be less than "234".

David


[Non-text portions of this message have been removed]

------------------------------------
----------------------------------
e sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here:
ttp://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES
or EXCEL VBA.
----------------------------------
isit our ExcelVBA group home page for more info and support files:
ttp://groups.yahoo.com/group/ExcelVBA
----------------------------------
ore free tutorials and resources available at:
ttp://www.mousetrax.com
----------------------------------Yahoo! Groups Links
Individual Email | Traditional
http://docs.yahoo.com/info/terms/

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity:
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------
.

__,_._,___

Tidak ada komentar:

Posting Komentar