Kamis, 05 Januari 2012

[ExcelVBA] Re: Sorting in VBA

 

Lisa --
Was your question "is contcatonating all the keys into a single field that is then used as the sort field the same as sorting the array on each key in sequence?" ?

You can create a mega-key by concatonating all the keys together but you must separate the keys by a delimiter that is not in the content of the keys. I use a <tab> for this (chr(9)) since it is highly unlikely in Excel cell content. thus your concatonation becomes
megakey = key1 & vbtab & key2 & vbtab .......

you also can achieve the result by sorting the array on each key in sequence, but you need to start with the least significant key and progress toward the most significant key. (on columns 6, then 4, then 1, and finally 0 in your example. You will also need a sort algorithm (if you are not using Excel's) that preserves the relative order of the lower-significant keys in the case of a "compare-equal' at a higher level. (If, when you are comparing on column 6 and two values are equal, your algorithm must not move the records out of order with respect to what you already determined when you sorted column 4. (If values are unequal in column 6, then the sort order in column 4 is meaningless).

db

--- In ExcelVBA@yahoogroups.com, "David Smart" <smartware.consulting@...> wrote:
>
> The use of multiple sort keys in a sort will depend entirely on the code you
> are using. Could you post it please?
>
> Regards, Dave S
>
> ----- Original Message -----
> From: "lisafaygreen" <1z@...>
> To: <ExcelVBA@yahoogroups.com>
> Sent: Friday, January 06, 2012 4:32 AM
> Subject: [ExcelVBA] Sorting in VBA
>
>
> > Hi y'all,
> >
> > I have a medium sized array and want to sort it on more than one element
> > in the 2nd dimension.
> >
> > Dim slA(500,9) As String
> >
> > For example on "Columns" 0 then 1 then 6 then 4 of the (9) Dimension...
> > Hope that makes sense. :-)
> >
> > Can anyone tell me for *definate* wether sorting in a complex way of...
> > (briefly) ...
> >
> > Extracting a seperate array of the same elements from 1
> > Sorting on 0
> > Extracting a seperate array of the same elements from 0
> > Sorting on 6
> > ... etc
> >
> > ... is the same as
> > Concatonating all of the fields in the required order
> > Sorting
> >
> > I know I could dump to a sheet and use Excels sort but I want to use the
> > code in Access and Word as well... hence the array.
> >
> > I really can't seem to get my head around it!! :-(
> >
> > TIA
> > Lisa
> >
> >
> >
> >
> >
> >
> >
> >
> > Wishing you all a great 2012!!
> >
> > Lisa
> >
> >
> >
> > ------------------------------------
> >
> > ----------------------------------
> > 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
> >
> > ----------------------------------Yahoo! Groups Links
> >
> >
> >
> >
> >
> > -----
> > No virus found in this message.
> > Checked by AVG - www.avg.com
> > Version: 10.0.1416 / Virus Database: 2109/4124 - Release Date: 01/05/12
> >
>

__._,_.___
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

----------------------------------
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

Tidak ada komentar:

Posting Komentar