我正在处理这个代码,其中有两个嵌套循环,并且在指示的行中出现编译错误“Next without for”
Sub Isindenm()
Dim wb As Workbook
Dim ws As Worksheet
Dim B As Integer
Dim firstrow As Integer
Dim lLastRow As Long
lLastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For firstrow = 14 To lLastRow
For B = 7 To 16
If IsNumeric(Cells(firstrow, B)) = True Then
Next B ***<-------------------Compile error:"next without for"***
Else
Cells(firstrow, 19) = Cells(firstrow, B)
End If
Next firstrow
End Sub
答案 0 :(得分:1)
将For
循环更改为:
For firstrow = 14 To lLastRow
For B = 7 To 16
If IsNumeric(Cells(firstrow, B)) = True Then
'Do something here if cell is numeric.
Else
'Do something here if cell is not numeric.
End If
Next B
Next firstrow
由于If
在For
循环内启动,它应该在调用Next firstRow
之前结束。