|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub TEST2()
Dim ar, br, i&, j&, n&
Application.ScreenUpdating = False
ar = Sheets("原数据").[A1].CurrentRegion.Value
For i = 1 To UBound(ar)
br = Application.Index(ar, i)
ShellSort1D br, 1, UBound(br)
n = 0
For j = 1 To UBound(br)
ar(i, j) = ""
If Len(br(j)) Then n = n + 1: ar(i, n) = br(j)
Next j
Next i
Cells.Clear
[A1].Resize(UBound(ar), UBound(ar, 2)) = ar
Application.ScreenUpdating = True
Beep
End Sub
Function ShellSort1D(ByRef ar, ByVal iFirst&, _
ByVal iLast&, Optional isOrder As Boolean = True)
Dim iRowSize&, vTemp, interval&, i&, j&, k&
ReDim vTemp(iFirst To iLast)
iRowSize = iLast - iFirst + 1
interval = 1
If iRowSize > 13 Then
Do While interval < iRowSize
interval = interval * 3 + 1
Loop
interval = interval \ 9
End If
Do While interval
For i = iFirst + interval To iLast
vTemp = ar(i)
If isOrder Then
For k = i - interval To iFirst Step -interval
If ar(k) <= vTemp Then Exit For
ar(k + interval) = ar(k)
Next k
Else
For k = i - interval To iFirst Step -interval
If ar(k) > vTemp Then Exit For
ar(k + interval) = ar(k)
Next k
End If
ar(k + interval) = vTemp
Next i
interval = interval \ 3
Loop
End Function
|
评分
-
1
查看全部评分
-
|