我在for循环中添加了跳转语句,有时可以顺畅运行,有时不能运行但不报错,不知是啥原因。
语句如下:
Sub aa()
Dim x%, y%
Line:
For x = 1 To 56
For y = 1 To 56
If x = yThen
Cells(x, y).Interior.ColorIndex = WorksheetFunction.RandBetween(1, 56)
Cells(x, 57 - y).Interior.ColorIndex = WorksheetFunction.RandBetween(1,56)
End If
Next y
Next x
GoTo Line
End Sub
楼上说的没错,死循环,本质上就是do loop的翻版,你想要的应该是附件上的效果吧
Sub test()
Dim i%
For i = 1 To 56
Cells(i, i).Interior.ColorIndex = Application.RandBetween(1, 56)
Cells(i, 57 - i).Interior.ColorIndex = Application.RandBetween(1, 56)
Next
Application.OnTime Now + TimeValue("00:00:01"), "test"
End Sub
感觉没必要跳转,也没必要设变量y。
Sub aa()
Dim x%
For x = 1 To 56
Cells(x, x).Interior.ColorIndex = WorksheetFunction.RandBetween(1, 56)
Cells(x, 57 - x).Interior.ColorIndex = WorksheetFunction.RandBetween(1,56)
Next x
End Sub
感觉没必要跳转,也没必要设变量y。
Sub aa()
Dim x%
For x = 1 To 56
Cells(x, x).Interior.ColorIndex = WorksheetFunction.RandBetween(1, 56)
Cells(x, 57 - x).Interior.ColorIndex = WorksheetFunction.RandBetween(1,56)
Next x
End Sub
楼上说的没错,死循环,本质上就是do loop的翻版,你想要的应该是附件上的效果吧
Sub test()
Dim i%
For i = 1 To 56
Cells(i, i).Interior.ColorIndex = Application.RandBetween(1, 56)
Cells(i, 57 - i).Interior.ColorIndex = Application.RandBetween(1, 56)
Next
Application.OnTime Now + TimeValue("00:00:01"), "test"
End Sub