Hi all,
I have a web scraper that pulls various sports teams' scores and puts each separate teams' scores into a different sheet. I've started scraping upwards of 200 teams a time, so I implemented the QuickSort algorithm as a means for sorting my sheets. The sort works perfectly when ascending, but I tried modifying the QuickSort code to sort descending and it stays as ascending. I've read multiple posts on the subject and they all modify the QuickSort code in the same fashion that I did, so I'm unsure where I'm going wrong. Any help would be greatly appreciated. Here's my code for creating my array to be sorted and then the QuickSort code I found online:
I have a web scraper that pulls various sports teams' scores and puts each separate teams' scores into a different sheet. I've started scraping upwards of 200 teams a time, so I implemented the QuickSort algorithm as a means for sorting my sheets. The sort works perfectly when ascending, but I tried modifying the QuickSort code to sort descending and it stays as ascending. I've read multiple posts on the subject and they all modify the QuickSort code in the same fashion that I did, so I'm unsure where I'm going wrong. Any help would be greatly appreciated. Here's my code for creating my array to be sorted and then the QuickSort code I found online:
Rich (BB code):
Sub call_sort()
Dim myArray() As Variant
x = Worksheets.Count
ReDim myArray(5 To x)
For i = 5 To x
myArray(i) = Worksheets(i).Name
Next i
Application.Run "Personal.xlsb!quick_sort_asc", myArray, LBound(myArray), UBound(myArray)
For i = 5 To x
Worksheets(myArray(i)).Move Before:=Worksheets(i)
Next i
End Sub
Rich (BB code):
Public Sub quick_sort_asc(ByRef vArray As Variant, inLow As Long, inHi As Long)
Dim tmpLow As Long, tmpHi As Long
Dim pivot As Variant, tmpSwap As Variant
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
Do While (tmpLow <= tmpHi)
Do While (vArray(tmpLow) < pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Loop
Do While (pivot < vArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Loop
If (tmpLow <= tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Loop
If (inLow < tmpHi) Then quick_sort_asc vArray, inLow, tmpHi
If (tmpLow < inHi) Then quick_sort_asc vArray, tmpLow, inHi
End Sub
*** Lines modified for Descending ***
Do While (vArray(tmpLow) > pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Loop
Do While (pivot > vArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Loop