|
Option Explicit
Sub test1()
Dim ar, br, i&, p&
With [A1].CurrentRegion.Offset(1)
p = 1
ar = .Value
For i = 1 To UBound(ar) - 1
If Len(ar(i, 1)) = False Then ar(i, 1) = ar(i - 1, 1)
Next i
For i = 1 To UBound(ar) - 1
If ar(i + 1, 1) <> ar(p, 1) Then
With .Cells(p, 2).Resize(i - p + 1, 2)
br = .Value
bSort br, 1, UBound(br), 1, 2, 2, False
.Value = br
p = i + 1
End With
End If
Next i
End With
End Sub
Function bSort(ByRef ar, ByVal iFirst&, ByVal iLast&, ByVal iLeft&, _
ByVal iRight&, ByVal iKey&, Optional isOrder As Boolean = True)
Dim i&, j&, k&, vTemp
For i = iFirst To iLast - 1
For j = iFirst To iLast + iFirst - 1 - i
If ar(j, iKey) <> ar(j + 1, iKey) Then
If ar(j, iKey) < ar(j + 1, iKey) Xor isOrder Then
For k = iLeft To iRight
vTemp = ar(j, k)
ar(j, k) = ar(j + 1, k)
ar(j + 1, k) = vTemp
Next
End If
End If
Next j
Next i
End Function
|
|