putting #s in order

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
I have some numbers that I put in an array like this:

sub GetNumbers()
range("a1").select
for I = 1 to 10

numbers(I) = activecell
activecell.offset(1,0).select

next I

end sub

Now I want to sort them from highest to lowest.
I have gotten some other code but I don't know how to apply it to my problem and I can't get any other responses.

Thank You
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

opinsky

New Member
Joined
Sep 26, 2006
Messages
21
You may want to look here for alternatives: http://en.wikipedia.org/wiki/Sorting_algorithm

bubble sort, the most popular, work like this:

function bubble_sort(list L, number listsize)
loop
has_swapped := 0 //reset flag
for number i from 1 to (listsize - 1)
if L > L[i + 1] //if they are in the wrong order
swap(L, L[i + 1]) //exchange them
has_swapped := 1 //we have swapped at least once, list may not be sorted yet
endif
endfor
//if no swaps were made during this pass, the list has been sorted
if has_swapped = 0
exit
endif
endloop
endfunction
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
You don't need to do all this selecting. You can work with ranges without selecting anything.
 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
What I wrote is an example.

The numbers I select are all over the spreadsheet.

Is there a way I can select thses cells and sort them without changing where they are on the spreadsheet?
 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640

ADVERTISEMENT

I got it

thank you
 

Forum statistics

Threads
1,141,718
Messages
5,708,074
Members
421,545
Latest member
TWR

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top