Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Sort on two columns in two dimensional array

Hi folks,

I am trying to figure out how to sort a two dimensional array by first
element 0, then element 1. I am struggling!! Can someone offer me
some help?

My array is arySort(4, 50)

Cheers,
Al
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort on two columns in two dimensional array

Paste it into a dummy sheet

use excel's sort

pick it back up.

--
Regards,
Tom Ogilvy

"Al" wrote in message
om...
Hi folks,

I am trying to figure out how to sort a two dimensional array by first
element 0, then element 1. I am struggling!! Can someone offer me
some help?

My array is arySort(4, 50)

Cheers,
Al



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Sort on two columns in two dimensional array

Al,

I'm somewhat confused. A two dimensional array would
look something like:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Entry(1,1) | Entry(1,2) | Entry(1,3) | Entry (1,4)
-+------------+------------+------------+------------
2| Entry(2,1) | Entry(2,2) | Entry(2,3) | Entry (2,4)
-+------------+------------+------------+------------
3| Entry(3,1) | Entry(3,2) | Entry(3,3) | Entry (3,4)

Another way of thinking about the problem would be:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Entry1 | Entry2 | Entry3 | Entry4
-+------------+------------+------------+------------
2| Entry5 | Entry6 | Entry7 | Entry8
-+------------+------------+------------+------------
3| Entry9 | Entry10 | Entry11 | Entry12


All you want to do is sort "Entry1"
through "Entry12"? I'm confused about sorting in one
direction and then the other? What are your entrys
(Numbers, Strings)?

David Fixemer

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Sort on two columns in two dimensional array

Hi David,

My array looks something like this:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Fund# | Test# | Currency | Balance
-+------------+------------+------------+------------
2| Fund# | Test# | Currency | Balance
-+------------+------------+------------+------------
3| Fund# | Test# | Currency | Balance

I would like to be able sort on Fund# then Test# so I have the
following:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| FundA | TestB | Currency | Balance
-+------------+------------+------------+------------
2| FundB | TestA | Currency | Balance
-+------------+------------+------------+------------
3| FundB | TestB | Currency | Balance

The elements are all strings. I know I could dump to a worksheet then
do a sort that way, but I would rather do it via code for speed. And
so I learn how to do it!!

Thanks very much,
Al


"David Fixemer" wrote in message ...
Al,

I'm somewhat confused. A two dimensional array would
look something like:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Entry(1,1) | Entry(1,2) | Entry(1,3) | Entry (1,4)
-+------------+------------+------------+------------
2| Entry(2,1) | Entry(2,2) | Entry(2,3) | Entry (2,4)
-+------------+------------+------------+------------
3| Entry(3,1) | Entry(3,2) | Entry(3,3) | Entry (3,4)

Another way of thinking about the problem would be:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Entry1 | Entry2 | Entry3 | Entry4
-+------------+------------+------------+------------
2| Entry5 | Entry6 | Entry7 | Entry8
-+------------+------------+------------+------------
3| Entry9 | Entry10 | Entry11 | Entry12


All you want to do is sort "Entry1"
through "Entry12"? I'm confused about sorting in one
direction and then the other? What are your entrys
(Numbers, Strings)?

David Fixemer

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Sort on two columns in two dimensional array

Thanks Tom, I just wondered if there was a way to code this for speed
of execution and neatness.

Cheers,
Al

"Tom Ogilvy" wrote in message ...
Paste it into a dummy sheet

use excel's sort

pick it back up.

--
Regards,
Tom Ogilvy

"Al" wrote in message
om...
Hi folks,

I am trying to figure out how to sort a two dimensional array by first
element 0, then element 1. I am struggling!! Can someone offer me
some help?

My array is arySort(4, 50)

Cheers,
Al



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sort on two columns in two dimensional array

Maybe it isn't that slow:

Dim ary as Variat
ary = Activesheet.Range("A1").CurrentRegion
worksheets.Add
Range("A1").resize(ubound(ary,1)-lbound(ary,1)+1, _
Ubound(ary,2)-lbound(ary,2)+1).Value = Ary
Range("A1").CurrentRegion.Sort _
Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order1:=xlAscending, _
Header:=xlNo
ary = Range("A1").CurrentRegion
Application.DisplayAlerts = False
activesheet.Delete
Application.DisplayAlerts = True

I don't know if what techniques you use, so the above may be old hat to you,
but then again, maybe it isn't.

I have never seen an algorithm posted to do multiple keys. I suspect the
algorithm is to do the sort on the first key, then loop through the array
and identify the rows that are identical in the first key position and pass
in these arguments to the sort routine to sort this subset on the second
key. The quicksort algorithm I have seen has parameters to identify a
subsection of the array.

You can search on http://groups.google.com, go to advanced search, search
on quicksort and Rech, this newsgroup, ogilvy as author. Restrict to May
2003 to present or use this link

http://tinyurl.com/yv6tp



--
Regards,
Tom Ogilvy



"Al" wrote in message
om...
Thanks Tom, I just wondered if there was a way to code this for speed
of execution and neatness.

Cheers,
Al

"Tom Ogilvy" wrote in message

...
Paste it into a dummy sheet

use excel's sort

pick it back up.

--
Regards,
Tom Ogilvy

"Al" wrote in message
om...
Hi folks,

I am trying to figure out how to sort a two dimensional array by first
element 0, then element 1. I am struggling!! Can someone offer me
some help?

My array is arySort(4, 50)

Cheers,
Al



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Sort on two columns in two dimensional array

Al,

I've read all of Tom's and your comments and it
appears you two either have it worked out, or will get it
worked out. That is greate considering I didn't even
understand the problem. Overnight (Drive Home) I
considered your problem a little more. Your reply simply
reinforced my conculsions. My previous post had the
elements already in order. If it actually looked like
this:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Entry1 | Entry11 | Entry10 | Entry4
-+------------+------------+------------+------------
2| Entry5 | Entry3 | Entry2 | Entry8
-+------------+------------+------------+------------
3| Entry9 | Entry7 | Entry6 | Entry12


Then you would desire a list like one of the following,
depending on weather you sort by row or column first?

Entry1 Entry1
Entry4 Entry5
Entry10 Entry9
Entry11 -------
------- Entry3
Entry2 Entry7
Entry3 Entry11
Entry5 -------
Entry8 Entry2
------- Entry6
Entry6 Entry10
Entry7 -------
Entry9 Entry4
Entry12 Entry8
Entry12
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Sort on two columns in two dimensional array

Sorting algorithms have exercised the minds of programmers for as long as we
have had the ability to programme (and possibly before). There are numerous
books on the subject, but the ones I have found useful a

Algorithms, by John Sedgewick, this seems to come in a number of flavours
with the examples having been written in different programming languages,
the ISBN numbers I have a

0-201-88863-7 softback, language C++ (but bought in Phillipines)
0-201-06673-4 hardback, language Pascal (nicer book though)

I'm sure there are many others, and probably more uptodate also.

Not sure whether this helps, but hope so.

Peter
"Tom Ogilvy" wrote in message
...
Maybe it isn't that slow:

Dim ary as Variat
ary = Activesheet.Range("A1").CurrentRegion
worksheets.Add
Range("A1").resize(ubound(ary,1)-lbound(ary,1)+1, _
Ubound(ary,2)-lbound(ary,2)+1).Value = Ary
Range("A1").CurrentRegion.Sort _
Key1:=Range("A1"), Order1:=xlAscending, _
Key2:=Range("B1"), Order1:=xlAscending, _
Header:=xlNo
ary = Range("A1").CurrentRegion
Application.DisplayAlerts = False
activesheet.Delete
Application.DisplayAlerts = True

I don't know if what techniques you use, so the above may be old hat to

you,
but then again, maybe it isn't.

I have never seen an algorithm posted to do multiple keys. I suspect the
algorithm is to do the sort on the first key, then loop through the array
and identify the rows that are identical in the first key position and

pass
in these arguments to the sort routine to sort this subset on the second
key. The quicksort algorithm I have seen has parameters to identify a
subsection of the array.

You can search on http://groups.google.com, go to advanced search,

search
on quicksort and Rech, this newsgroup, ogilvy as author. Restrict to

May
2003 to present or use this link

http://tinyurl.com/yv6tp



--
Regards,
Tom Ogilvy



"Al" wrote in message
om...
Thanks Tom, I just wondered if there was a way to code this for speed
of execution and neatness.

Cheers,
Al

"Tom Ogilvy" wrote in message

...
Paste it into a dummy sheet

use excel's sort

pick it back up.

--
Regards,
Tom Ogilvy

"Al" wrote in message
om...
Hi folks,

I am trying to figure out how to sort a two dimensional array by

first
element 0, then element 1. I am struggling!! Can someone offer me
some help?

My array is arySort(4, 50)

Cheers,
Al





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Sort on two columns in two dimensional array

Peter,

Thanks for that. I can't find the first book ISBN anywhere on the
web, but the second one turned up several books by Robert Sedgewick on
Amazon - might invest in one of those, so thanks for the tip!!

Cheers,
Al


"Peter M" wrote in message ...
Sorting algorithms have exercised the minds of programmers for as long as we
have had the ability to programme (and possibly before). There are numerous
books on the subject, but the ones I have found useful a

Algorithms, by John Sedgewick, this seems to come in a number of flavours
with the examples having been written in different programming languages,
the ISBN numbers I have a

0-201-88863-7 softback, language C++ (but bought in Phillipines)
0-201-06673-4 hardback, language Pascal (nicer book though)

I'm sure there are many others, and probably more uptodate also.

Not sure whether this helps, but hope so.

Peter

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Sort on two columns in two dimensional array

Hi David,

Thanks for the message - as per Toms suggestion (thanks!), I ended up
dumping the data to a worksheet and doing a data sort on it before
reading it back in.

Cheers,
Al


"David Fixemer" wrote in message ...
Al,

I've read all of Tom's and your comments and it
appears you two either have it worked out, or will get it
worked out. That is greate considering I didn't even
understand the problem. Overnight (Drive Home) I
considered your problem a little more. Your reply simply
reinforced my conculsions. My previous post had the
elements already in order. If it actually looked like
this:

| 1 | 2 | 3 | 4
-+------------+------------+------------+------------
1| Entry1 | Entry11 | Entry10 | Entry4
-+------------+------------+------------+------------
2| Entry5 | Entry3 | Entry2 | Entry8
-+------------+------------+------------+------------
3| Entry9 | Entry7 | Entry6 | Entry12


Then you would desire a list like one of the following,
depending on weather you sort by row or column first?

Entry1 Entry1
Entry4 Entry5
Entry10 Entry9
Entry11 -------
------- Entry3
Entry2 Entry7
Entry3 Entry11
Entry5 -------
Entry8 Entry2
------- Entry6
Entry6 Entry10
Entry7 -------
Entry9 Entry4
Entry12 Entry8
Entry12

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I need a two dimensional array for this? hotherps[_17_] Excel Programming 1 February 20th 04 04:46 PM
2 Dimensional Array steve Excel Programming 0 August 18th 03 07:19 PM
Beginners' Question : How to move selected columns & rows to a two dimensional array Erche DP Excel Programming 3 July 18th 03 03:25 PM
Beginners' Question : How to move selected columns & rows to a two dimensional array Erche Excel Programming 4 July 18th 03 04:19 AM
sort multi-dimensional array on numeric data? RB Smissaert Excel Programming 0 July 14th 03 10:49 PM


All times are GMT +1. The time now is 03:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"