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
1
  • 4
    You can't interleave for next and if then like that. Change your if to If Not IsNumeric(Cells(firstRow, "B")) Then Commented Nov 17, 2013 at 23:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.