0

I'm working on this code in which there are two nested loops and I get a compile error "Next without for" in the line indicated

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
Community
  • 1
  • 1
user3002790
  • 195
  • 1
  • 2
  • 5
  • 4
    You can't interleave for next and if then like that. Change your if to `If Not IsNumeric(Cells(firstRow, "B")) Then` – Tim Williams Nov 17 '13 at 23:43

1 Answers1

1

Change the For loop to:

  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

Since If started inside the For loop, it should end before the call to the Next firstRow.

WGS
  • 13,969
  • 4
  • 48
  • 51