Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I do I sort an array in VBA. -- ditzafar ------------------------------------------------------------------------ ditzafar's Profile: http://www.excelforum.com/member.php...o&userid=29475 View this thread: http://www.excelforum.com/showthread...hreadid=542836 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Do the sort in Excel with the macro recorder turned on. This will create
your code. -- HTH Bob Phillips (remove xxx from email address if mailing direct) "ditzafar" wrote in message ... I do I sort an array in VBA. -- ditzafar ------------------------------------------------------------------------ ditzafar's Profile: http://www.excelforum.com/member.php...o&userid=29475 View this thread: http://www.excelforum.com/showthread...hreadid=542836 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is one way, posted by Tom Ogilvy
-- Kind regards, Niek Otten ================================================== ======== Sub QuickSort(SortArray, col, L, R, bAscending) ' 'Originally Posted by Jim Rech 10/20/98 Excel.Programming 'Modified to sort on first column of a two dimensional array 'Modified to handle a second dimension greater than 1 (or zero) 'Modified to do Ascending or Descending Dim i, j, X, Y, mm i = L j = R X = SortArray((L + R) / 2, col) If bAscending Then While (i <= j) While (SortArray(i, col) < X And i < R) i = i + 1 Wend While (X < SortArray(j, col) And j L) j = j - 1 Wend If (i <= j) Then For mm = LBound(SortArray, 2) To UBound(SortArray, 2) Y = SortArray(i, mm) SortArray(i, mm) = SortArray(j, mm) SortArray(j, mm) = Y Next mm i = i + 1 j = j - 1 End If Wend Else While (i <= j) While (SortArray(i, col) X And i < R) i = i + 1 Wend While (X SortArray(j, col) And j L) j = j - 1 Wend If (i <= j) Then For mm = LBound(SortArray, 2) To UBound(SortArray, 2) Y = SortArray(i, mm) SortArray(i, mm) = SortArray(j, mm) SortArray(j, mm) = Y Next mm i = i + 1 j = j - 1 End If Wend End If If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending) If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending) End Sub Sub aaTesterSort() Dim bAscending As Boolean Set rng = Range("I7").CurrentRegion vArr = rng.Value bAscending = False QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1), bAscending Range("I26").Resize(UBound(vArr, 1), UBound(vArr, 2)).Value = vArr End Sub "ditzafar" wrote in message ... | | I do I sort an array in VBA. | | | -- | ditzafar | ------------------------------------------------------------------------ | ditzafar's Profile: http://www.excelforum.com/member.php...o&userid=29475 | View this thread: http://www.excelforum.com/showthread...hreadid=542836 | |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
This will sort a worksheet range called "TestRange" on the activesheet. It willleave the first row (headings) alone Public Sub SortTheTestRange() Dim DataRange As Range Set DataRange = ActiveSheet.Range("TestRange") With DataRange .Sort _ Key1:=.Cells(1, 1), Order1:=xlAscending, _ Key2:=.Cells(1, 2), Order2:=xlAscending, _ Key3:=.Cells(1, 3), Order3:=xlAscending, _ header:=xlYes 'first row is not sorted End With End Sub regards Paul |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Updating workbook with an alpha sort sheet and a numeric sort shee | Excel Discussion (Misc queries) | |||
sort function for dates does not sort properly in Office 2007 Exc. | Excel Worksheet Functions | |||
Pls. reply Sort Data and copy to next coulmn when sort order chang | Excel Programming | |||
Excel sort by Fill Color by custom list sort | Excel Discussion (Misc queries) | |||
sort (on part of) string - originally posted under Tricky Sort | Excel Programming |