Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have xl2002. In in VBA. I have a vector (or one column matrix) of short
strings. I'd like to sort them. Is the easiest way to place them on a sheet someplace, run sort, and then read them back in? Don <donwiss at panix.com. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() "Don Wiss" wrote in message ... I have xl2002. In in VBA. I have a vector (or one column matrix) of short strings. I'd like to sort them. Is the easiest way to place them on a sheet someplace, run sort, and then read them back in? Don <donwiss at panix.com. Use Data|Sort... |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Fredrik Wahlgren wrote:
Don Wiss wrote: I have xl2002. In in VBA. I have a vector (or one column matrix) of short strings. I'd like to sort them. Is the easiest way to place them on a sheet someplace, run sort, and then read them back in? Use Data|Sort... Uh, what does this have to do with a macro? I know how to use a macro to sort on a sheet. I asked if that was the only way, as the strings are in a macro and will end up only in the macro. Don <donwiss at panix.com. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This example builds an array of filenames and then sorts them.
Sub UpdateFileLB() Dim Fname As String, FileArray() As String Dim FCounter As Long Fname = Dir("C:\excel\files\*.xls") Do While Fname < "" FCounter = FCounter + 1 ReDim Preserve FileArray(1 To FCounter) FileArray(FCounter) = Fname Fname = Dir() Loop QuickSort FileArray, 1, FCounter End Sub Sub QuickSort(SortArray, L As Long, R As Long) ' L is the lower bound of the array ' R is the upper bound of the array Dim I As Long, J As Long, x As Variant, Y As Variant I = L J = R x = SortArray((L + R) / 2) While (I <= J) While (SortArray(I) < x And I < R) I = I + 1 Wend While (x < SortArray(J) And J L) J = J - 1 Wend If (I <= J) Then Y = SortArray(I) SortArray(I) = SortArray(J) SortArray(J) = Y I = I + 1 J = J - 1 End If Wend If (L < J) Then Call QuickSort(SortArray, L, J) If (I < R) Then Call QuickSort(SortArray, I, R) End Sub -- Regards, Tom Ogilvy "Don Wiss" wrote in message ... I have xl2002. In in VBA. I have a vector (or one column matrix) of short strings. I'd like to sort them. Is the easiest way to place them on a sheet someplace, run sort, and then read them back in? Don <donwiss at panix.com. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Sun, 9 Jan 2005 19:41:53 -0500, "Tom Ogilvy" wrote:
This example builds an array of filenames and then sorts them. Sub QuickSort(SortArray, L As Long, R As Long) [snipped..] Thanks. Works beautifully. Now after this I will remove duplicates. Possibly something that could (optionally) be inside QuickSort. Don <donwiss at panix.com. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You may want to look at the way John Walkenbach did it:
http://j-walk.com/ss/excel/tips/tip47.htm Don Wiss wrote: On Sun, 9 Jan 2005 19:41:53 -0500, "Tom Ogilvy" wrote: This example builds an array of filenames and then sorts them. Sub QuickSort(SortArray, L As Long, R As Long) [snipped..] Thanks. Works beautifully. Now after this I will remove duplicates. Possibly something that could (optionally) be inside QuickSort. Don <donwiss at panix.com. -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Sun, 09 Jan 2005, Dave Peterson wrote:
Don Wiss wrote: Now after this I will remove duplicates. Possibly something that could (optionally) be inside QuickSort. You may want to look at the way John Walkenbach did it: http://j-walk.com/ss/excel/tips/tip47.htm Interesting. I have never used a collection. Nor been aware of them. Though now in sorted order removing duplicates is trivial, and I do need it to be sorted for the next step. Don <donwiss at panix.com. |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
John had a sort in that sample code, too.
Don Wiss wrote: On Sun, 09 Jan 2005, Dave Peterson wrote: Don Wiss wrote: Now after this I will remove duplicates. Possibly something that could (optionally) be inside QuickSort. You may want to look at the way John Walkenbach did it: http://j-walk.com/ss/excel/tips/tip47.htm Interesting. I have never used a collection. Nor been aware of them. Though now in sorted order removing duplicates is trivial, and I do need it to be sorted for the next step. Don <donwiss at panix.com. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Help with Macro for sorting | Excel Worksheet Functions | |||
sorting using macro | Excel Discussion (Misc queries) | |||
Macro for Sorting | Excel Programming | |||
Sorting with a macro? | Excel Programming | |||
Sorting w/Macro | Excel Programming |