Sorting

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
690
Office Version
  1. 365
Platform
  1. Windows
I have an array of numbers that I want to sort from highest to lowest.



Numbers(100)
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,792
Members
449,048
Latest member
greyangel23

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