|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim r%, i%, s%
- Dim arr, brr
- Randomize Timer
- With Worksheets("sheet1")
- r = .Cells(.Rows.Count, 12).End(xlUp).Row
- brr = .Range("l2:o" & r)
- For j = 1 To 3 Step 2
- For i = 1 To UBound(brr) - 1
- m = Int(Rnd() * (UBound(brr) - i)) + i + 1
- For k = 0 To 1
- temp = brr(i, j + k)
- brr(i, j + k) = brr(m, j + k)
- brr(m, j + k) = temp
- Next
- Next
- Next
- s = 0
- Do
- For i = 1 To UBound(brr)
- If brr(i, 2) = brr(i, 4) Then
- For j = 1 To UBound(brr)
- If i <> j Then
- If brr(j, 2) <> brr(i, 4) And brr(j, 4) <> brr(i, 4) Then
- For k = 3 To 4
- temp = brr(i, k)
- brr(i, k) = brr(j, k)
- brr(j, k) = temp
- Next
- Exit For
- End If
- End If
- Next
- If j > UBound(brr) Then
- s = s + 1
- End If
- End If
- Next
- Loop Until s = 0
- .Range("b2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|