|
良く解ってないけど見本。
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub aaaa()
Dim 上下左右 As Long, 歩 As Long
Cells(10, 10).Select
Sleep 200
Randomize
上下左右 = Int((4 * Rnd) + 1)
歩 = Int((10 * Rnd) + 1)
With ActiveCell
For i = 1 To 歩
If 上下左右 = 1 Then
If ActiveCell.Row > 1 Then
ActiveCell.Offset(-1).Select
Else
Exit For
End If
ElseIf 上下左右 = 2 Then
If ActiveCell.Row < Rows.Count Then
ActiveCell.Offset(1).Select
Else
Exit For
End If
ElseIf 上下左右 = 3 Then
If ActiveCell.Column > 1 Then
ActiveCell.Offset(, -1).Select
Else
Exit For
End If
ElseIf 上下左右 = 4 Then
If ActiveCell.Column < Columns.Count Then
ActiveCell.Offset(, 1).Select
Else
Exit For
End If
End If
DoEvents
Sleep 100
Next
End With
End Sub
|
|