0

我做了一个嵌套的 For 循环,如图所示:

For i = 1 To 14
Set curCell_a = Worksheets("Sheet1").Cells(i, 6)    

If curCell_a.Value = 100 Then
Set curCell_b = curCell_a.Offset(3, -1)
cRow = curCell_b.Row     

For j = cRow To 15
Set curCell_c = Worksheets("Sheet1").Cells(cRow, 5)
While curCell_c.Font.Bold = False
MsgBox (curCell_c.Value)
End

Next j    
End If    
Next i

然而我不断收到错误Compile error: Next without For

我很确定我Next j, End If, and Next i按逻辑顺序排列...有人可以帮助我吗?太感谢了!

4

2 回答 2

1

我认为问题在于End声明:它应该是Wend(While-End)。

For i = 1 To 14

    Set curCell_a = Worksheets("Sheet1").Cells(i, 6)

    If curCell_a.Value = 100 Then

        Set curCell_b = curCell_a.Offset(3, -1)
        cRow = curCell_b.Row

        For j = cRow To 15
            Set curCell_c = Worksheets("Sheet1").Cells(cRow, 5)
            While curCell_c.Font.Bold = False
                MsgBox (curCell_c.Value)
            Wend
        Next j

    End If

Next i

请参阅http://office.microsoft.com/en-us/excel-help/HV080557576.aspx

于 2012-10-19T19:31:29.030 回答
0

while 块需要以 Wend 结束,而不是 End。编译器没有看到该块的结尾。

于 2012-10-19T19:34:56.503 回答