使用resize简捷多了。
Function sj(arr)
Dim i, d, t, m, n
m = Range("a18")
n = Range("a19")
For i = 1 To n
d = Int(Rnd * n + 1)
t = arr(i, 1)
arr(i, 1) = arr(d, 1)
arr(d, 1) = t
Next
sj = arr
End Function
Sub test()
Dim i, d, t, m, n
m = Range("a18")
n = Range("a19")
ReDim arr(1 To n, 1 To 1)
For i = 1 To n
arr(i, 1) = i
Next
Cells(1, 1).Resize(n, m) = ""
For i = 1 To m
X: arr = sj(arr)
Cells(1, i).Resize(n) = arr
For k = 1 To n
' If Application.CountIf(Range("a" & k).Resize(1, i), Cells(k, i)) > 1 Then GoTo X
If Application.CountIf(Cells(k, 1).Resize(1, i), Cells(k, i)) > 1 Then GoTo X
' If Application.CountIf(Cells(Cells(k, 1), Cells(k, i)), Cells(k, i)) > 1 Then GoTo X '****** 结果错误
Next k
Next i
End Sub
但这两句有什么区别呢?
If Application.CountIf(Cells(k, 1).Resize(1, i), Cells(k, i)) > 1 Then GoTo X
' If Application.CountIf(Cells(Cells(k, 1), Cells(k, i)), Cells(k, i)) > 1 Then GoTo X '****** 结果错误
|