If either of those two solutions were an option, I would not be asking the question.
Option Explicit
Private Sub CommandButton1_Click()
Dim r As Range
Dim i As Long
Dim strData() As String
Set r = Range("A1").End(xlDown).Offset(0, 0)
ReDim strData(1 To r.Row)
For i = 1 To r.Row
strData(i) = Range("A" & i)
Next
BubbleSortDec strData
For i = 1 To r.Row
Range("A" & i).Value = strData(i)
Next
End Sub
Public Sub BubbleSortDec(ByRef pvarArray As Variant)
Dim i As Long
Dim iMin As Long
Dim iMax As Long
Dim varSwap As Variant
Dim blnSwapped As Boolean
Dim strParts1() As String
Dim strParts2() As String
iMin = LBound(pvarArray)
iMax = UBound(pvarArray) - 1
Do
blnSwapped = False
For i = iMin To iMax
strParts1 = Split(pvarArray(i), "-")
strParts2 = Split(pvarArray(i + 1), "-")
If strParts1(0) < strParts2(0) Then
varSwap = pvarArray(i)
pvarArray(i) = pvarArray(i + 1)
pvarArray(i + 1) = varSwap
blnSwapped = True
End If
If strParts1(0) = strParts2(0) Then
If strParts1(1) > strParts2(1) Then
varSwap = pvarArray(i)
pvarArray(i) = pvarArray(i + 1)
pvarArray(i + 1) = varSwap
blnSwapped = True
End If
End If
Next
iMax = iMax - 1
Loop Until Not blnSwapped
End Sub
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
11 Experts available now in Live!