ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   code for organizing array (https://www.excelbanter.com/excel-programming/343084-code-organizing-array.html)

[email protected]

code for organizing array
 
Hi,

I am trying to organize an array that I have in VBA. Basically I have a
list that looks something like:

January 15
February 20
March 40
April 10

(the actual list has more columns and different type of data but the
idea is the same). What I would like is to have some code that can go
through the array and the producing a new array listing the 3 highest
values out of the 4. So the end result would look like:

April 10
January 15
February 20

Can anybody give me some help of how that code would look like? Also if
you can point me to how to find the answers to those kind of queries in
the future? I thought that posting it would be the best way but maybe
the answers are already present somewhere and I am just wasting
people's time (I have already bought some vba books but could not find
an answer in there). Thanks a lot!

rgds, Sergio


RB Smissaert

code for organizing array
 
You could sort the array and pick the first (or last) 3 rows.
You can pick array sorting routines up easily by doing a sort in Google.

The other option is just to loop through the rows of the array and pick up
the first 3 rows and then keep
replacing the one with the lowest value if there is a row with a higher
value.
The last option will be faster as it is all done in one pass.

RBS

wrote in message
ups.com...
Hi,

I am trying to organize an array that I have in VBA. Basically I have a
list that looks something like:

January 15
February 20
March 40
April 10

(the actual list has more columns and different type of data but the
idea is the same). What I would like is to have some code that can go
through the array and the producing a new array listing the 3 highest
values out of the 4. So the end result would look like:

April 10
January 15
February 20

Can anybody give me some help of how that code would look like? Also if
you can point me to how to find the answers to those kind of queries in
the future? I thought that posting it would be the best way but maybe
the answers are already present somewhere and I am just wasting
people's time (I have already bought some vba books but could not find
an answer in there). Thanks a lot!

rgds, Sergio




All times are GMT +1. The time now is 03:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com