|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
'试一下,估计差不多。如果数据量大换个快排
Option Explicit
Sub test()
Dim arr, sht, row, col, i, j, k, t, n
For Each sht In Sheets
With Sheets(sht.Name)
row = .Cells(Rows.Count, "k").End(xlUp).row
col = .Cells(2, Columns.Count).End(xlToLeft).Column
arr = Range(.[k2], .Cells(row, col))
If .[j2].Value = "one" Then
For j = 1 To UBound(arr, 2)
For i = 1 To UBound(arr, 1) - 1
For k = i + 1 To UBound(arr, 1)
If arr(i, j) > arr(k, j) Then
t = arr(i, j): arr(i, j) = arr(k, j): arr(k, j) = t
End If
Next k, i, j
Else
For i = 1 To UBound(arr, 1) - 1
For j = i + 1 To UBound(arr, 1)
If arr(i, 1) > arr(j, 1) Then
t = arr(i, 1): arr(i, 1) = arr(j, 1): arr(j, 1) = t
End If
Next j, i
For j = 2 To UBound(arr, 2)
Randomize
For i = 1 To UBound(arr, 1)
n = Int(Rnd * UBound(arr, 1)) + 1
t = arr(i, j): arr(i, j) = arr(n, j): arr(n, j) = t
Next i, j
End If
.[k2].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End With
Next
End Sub |
|