Hey David....
I've implemented your second suggestion but I'm afraid I can't just get my head around your first one.... yet :-) You go "forward" through the keylist for example where I thought it should go least to most sig.
I've also added code to make sorting numbers come out corectly.
If you check the project that this was for then you'll see I've added another treeview which is actually dependent on this sort. I haven't though added double click code for the new treeview because I need to tweak the node keys before I do.
When I've done that and am happy with everything working I'll repost the sort routine/s here.
Thank you for checking/looking at the code so critically!! Great! And thank you for the suggestions too!
Hugs
Lisa
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]
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