2x'循环'和1x'直到' – >不能运行macros

我正在尝试创build一个简单的algorithm来生成Sudoku游戏表。 我遇到了以下问题。 我的代码的主要部分是Do until循环。 但是当有两个“循环”短语时,我不能运行macros。 谁能告诉我这是为什么? 有什么办法来克服这个问题? 我非常感谢任何提示。 我也非常感谢(如果我是新来的论坛),如果你能让我知道我的post是模糊的还是不符合你的期望。
代码如下:(出现问题的时刻标有注释)
Sub MAIN()

Dim a, r, c, V As Integer r = 2 c = 2 Do Until r = 11 And c = 2 a = Sheets("LIST").Columns("B").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row - 1 V = Int(a * Rnd + 1) Sheets("GAME").Cells(r, c).Value = V If V = 5 Then 'This condition is a test-condition. In the final version of code there should be more sophisticated condition. Sheets("LIST").Range("B" & V - 1).Delete Shift:=xlUp Loop '(this is the first loop) End If If c = 10 Then r = r + 1 c = 2 Else c = c + 1 End If Sheets("LIST").Cells(2, 2).Value = 1 Sheets("LIST").Cells(2, 3).Value = 2 Sheets("LIST").Cells(2, 4).Value = 3 Sheets("LIST").Cells(2, 5).Value = 4 Sheets("LIST").Cells(2, 6).Value = 5 Sheets("LIST").Cells(2, 7).Value = 6 Sheets("LIST").Cells(2, 8).Value = 7 Sheets("LIST").Cells(2, 9).Value = 8 Sheets("LIST").Cells(2, 10).Value = 9 Loop '(this is the second loop) End Sub 

一个简单的说明(仅供参考),您可以使用With... End With结构节省大量的input:

 '... With Sheets("LIST") .Cells(2, 2) = 1 .Cells(3, 2) = 2 .Cells(4, 2) = 3 '... End With 

那么,如果你感觉真的很狂野,你可以使用For...Next循环填充你的sodoku广场:

 '... Dim SizeOfSquare As Long, Index As Long SizeOfSquare = 9 With Sheets("LIST") For Index = 1 To SizeOfSquare .Cells(Index + 1, 2) = Index Next Index End With 

懒惰并不总是一件坏事!

好吧,在我发布之后SECODN我想出了一个解决scheme!
我很抱歉,我已经把论坛弄糊涂了。 这是修改的代码:
(我会把它留在这里,以防有人会像我这样一个愚蠢的问题:))

 Sub MAIN() Dim a, r, c, V As Integer r = 2 c = 2 Do Until r = 11 And c = 2 a = Sheets("LIST").Columns("B").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row - 1 V = Int(a * Rnd + 1) Sheets("GAME").Cells(r, c).Value = V If V = 5 Then Sheets("LIST").Range("B" & V - 1).Delete Shift:=xlUp Else If c = 10 Then r = r + 1 c = 2 Else c = c + 1 End If Sheets("LIST").Cells(2, 2).Value = 1 Sheets("LIST").Cells(3, 2).Value = 2 Sheets("LIST").Cells(4, 2).Value = 3 Sheets("LIST").Cells(5, 2).Value = 4 Sheets("LIST").Cells(6, 2).Value = 5 Sheets("LIST").Cells(7, 2).Value = 6 Sheets("LIST").Cells(8, 2).Value = 7 Sheets("LIST").Cells(9, 2).Value = 8 Sheets("LIST").Cells(10, 2).Value = 9 End If Loop End Sub