Next without For error Message

  • Thread starter Todd Huttenstine
  • Start date
T

Todd Huttenstine

Can anyone tell me why when I try to run this code I get
the error message "Next without For"? Im not sure why I
am getting this since I do have a For statement in there.
If I were to remove the If Then Else statement then the
code loops just fine. But when I add the If Then Else
statement back in I get the Next without For error.

Dim rng2 As Range
Dim Destination As Object
Dim Replacement
Dim counter2
Dim numcount As Long

numcount = Application.WorksheetFunction.CountA(Sheets
("Converted Data").Range("O:O"))
counter2 = 1
Set rng2 = Sheets("Mismatches").Range("A2:A" & Range
("E1").Value)

For Each Destination In rng2
counter2 = counter2 + 1
Replacement = Sheets("Mismatches").Range("B" & counter2)
If Sheets("Mismatches").Range("B" & counter2) = "" Then
Else
Destination = Replacement
Next


Thanks
Todd Huttenstine
 
F

Frank Kabel

Hi Todd
you missed the End if statement. Try:

.....
For Each Destination In rng2
counter2 = counter2 + 1
Replacement = Sheets("Mismatches").Range("B" & counter2)
If Sheets("Mismatches").Range("B" & counter2) = "" Then
Else
Destination = Replacement
end if
Next
 
Top