Yikes!!
This is complicated ... congrats for getting it to work.
I find use of lngpLeft and lngpRight to as cursors for the rows being
compared, confusing as I think of row numbers being vertical (up/down) and
columns being horizontal (left/right)
It can be significantly simplified:
Leaving aside how the two entries to be compared are determined, the inner
guts can be done much simpler
Comparing multiple keys (compare on highest priority of remaining keys if
all higher priority keys are equal)
Following is combination of Meta and code..should be taken as suggestive..
For Col = lbound(ListOfKeyColumns) to
ubound(ListofKeyColumns)
Select case
strcomp(theArray(right_row,col),thearray(left_row,col),vbtextcompare)
Case 0: 'this and all prior
keys equal, compare next key
Case > 0 'out of order
(assuming ascending)
<Swap the
rows --- see below>
Exit for
Case < 0 'rows in correct
order (assuming ascending)
Case else
Msgbox "?I
am 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
ubound(theArray,2) 'assuming array is dimensioned as (Rows,Columns)
theTemp =
theArray(right_row, col)
theArray(right_row,col) =
theArray(left_row,col)
theArray(left_row,col) =
theTemp
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