|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub ykcbf() '//2025.3.25
- With ActiveSheet
- r = .Cells(Rows.Count, 3).End(3).Row
- arr = .Range("A2:C" & r).Value
- Dim tm: tm = Timer
- QuickSort arr, LBound(arr, 1), UBound(arr, 1)
- .Range("A2:C" & r).Value = arr
- End With
- MsgBox "共用时:" & Format(Timer - tm, "0.000") & "秒!"
- End Sub
- Sub QuickSort(ByRef dataArray As Variant, ByVal low As Long, ByVal high As Long)
- Dim i As Long, j As Long
- Dim pivot As Double
- Dim temp As Variant
- If low < high Then
- i = low
- j = high
- pivot = ston(dataArray((low + high) \ 2, 3))
- While i <= j
- While ston(dataArray(i, 3)) < pivot
- i = i + 1
- Wend
- While ston(dataArray(j, 3)) > pivot
- j = j - 1
- Wend
- If i <= j Then
- For k = 1 To 3
- temp = dataArray(i, k)
- dataArray(i, k) = dataArray(j, k)
- dataArray(j, k) = temp
- Next k
- i = i + 1
- j = j - 1
- End If
- Wend
- If low < j Then QuickSort dataArray, low, j
- If i < high Then QuickSort dataArray, i, high
- End If
- End Sub
- Function ston(st)
- Dim reg As Object
- Set reg = CreateObject("VBScript.RegExp")
- With reg
- .Pattern = "[^\d]"
- .Global = True
- .IgnoreCase = True
- End With
- ston = reg.Replace(st, "") * 1
- Set reg = Nothing
- End Function
复制代码
|
|