putting #s in order

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
693
Office Version
  1. 365
Platform
  1. Windows
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 came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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
 
Upvote 0
You don't need to do all this selecting. You can work with ranges without selecting anything.
 
Upvote 0
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?
 
Upvote 0

Forum statistics

Threads
1,216,380
Messages
6,130,291
Members
449,570
Latest member
TomMacca52

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
Back
Top