natalie123vba
New Member
- Joined
- Nov 30, 2022
- Messages
- 6
- Office Version
- 365
- Platform
- Web
Hi All, I am trying to sort a column in descending order using the If..then..else method. it worked for me in ascending order but I cant get it to work in descending. any help here would be appreciated. this is the code i used for ascending:
Sub sort_numbersUP()
Dim Sorted As Boolean
Sheets("Sheet1").Range("B5:B25").Copy Destination:=Sheets("Sheet1").Range("C5")
Do
Sorted = False
For numEntries = 5 To 25 - 2
If Cells(numEntries, 3).Value > Cells(numEntries + 1, 3).Value Then
tmpvar = Cells(numEntries + 1, 3)
Cells(numEntries + 1, 3).Value = Cells(numEntries, 3)
Cells(numEntries, 3).Value = tmpvar
Sorted = True
End If
Next
Loop While Sorted
End Sub
My descending column is (F28:F57)
Thanks
Sub sort_numbersUP()
Dim Sorted As Boolean
Sheets("Sheet1").Range("B5:B25").Copy Destination:=Sheets("Sheet1").Range("C5")
Do
Sorted = False
For numEntries = 5 To 25 - 2
If Cells(numEntries, 3).Value > Cells(numEntries + 1, 3).Value Then
tmpvar = Cells(numEntries + 1, 3)
Cells(numEntries + 1, 3).Value = Cells(numEntries, 3)
Cells(numEntries, 3).Value = tmpvar
Sorted = True
End If
Next
Loop While Sorted
End Sub
My descending column is (F28:F57)
Thanks