Sorting

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
I have an array of numbers that I want to sort from highest to lowest.



Numbers(100)
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
Sub ShellSort()
'Dave Braden's code
Dim i As Long, j As Long, inc As Long, list As Variant
Dim var As Variant, LowIndex As Integer, HiIndex As Long
Dim myArray$

'list = [{"Nate","Colo","Orange","Ivan"}]
list = [{2,1,4,3}]

LowIndex = LBound(list): HiIndex = UBound(list)
inc = 1

Do While inc <= HiIndex - LowIndex: inc = 3 * inc + 1: Loop
Do
inc = inc \ 3

For i = LowIndex + inc To HiIndex
var = list(i)
j = i

Do While list(j - inc) > var
list(j) = list(j - inc)
j = j - inc

If j <= inc Then Exit Do
Loop
list(j) = var
Next

Loop While inc > 1

For a = 1 To 3
myArray = myArray & list(a) & ", "
Next a

myArray = myArray & list(4)

MsgBox myArray
End Sub
 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
That certainly works well but I have no idea how to apply that to my spreadsheet..

What I have is


NUMBERS(1) = 237
NUMBERS(2) = 468
NUMBERS(3) = 15
NUMBERS(4) = 729
NUMBERS(5) = 333
NUMBERS(6) = 934

Would you please explain.

Marty
 

Forum statistics

Threads
1,141,097
Messages
5,704,314
Members
421,338
Latest member
Pepess

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