|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Option Explicit
Sub test1()
Dim ar, br, i&, j&
With [F8:T22]
ar = .Value
For i = 1 To UBound(ar)
br = Application.Index(ar, i)
Call arrGetRnd1(br)
For j = 1 To UBound(br)
ar(i, j) = br(j)
Next j
Next i
.Value = ar
End With
End Sub
Function arrGetRnd1(ByRef ar)
Dim br, xNum&, i&, n&, vTemp, xRnd&
ReDim br(1 To 2)
Randomize
n = UBound(ar)
For i = 1 To UBound(ar)
xNum = Int((n - i + 1) * Rnd() + i)
If ar(xNum) > ar(i) Then vTemp = ar(i) Else vTemp = ar(xNum)
vTemp = Int(vTemp / 10)
xRnd = Int(2 * Rnd() + 1)
If xRnd = 1 Then
br(1) = "+": br(2) = "-"
Else
br(1) = "-": br(2) = "+"
End If
ar(xNum) = Evaluate(ar(xNum) & br(1) & vTemp)
ar(i) = Evaluate(ar(i) & br(2) & vTemp)
Next
End Function
|
|