PDA

View Full Version : For loop trouble



dub
02-14-2011, 11:02 AM
Hello, I have two for loops that are nested with a bunch of if statments inside for comparing 4 variables from two different worksbooks. The loops are part of a a Do while that allows the workbook variable named "ab" to change for all files in the folder chosen. The "ad" workbook does not change and each "ab" file is compared to the "ad" file. I am trying report differences in the varible named "4_ab" and "4_ad" between the "ab" and "ad" files, respectively, as an error, but only when all the other three variable do match. The problem I am having is an error saying "Next without For" and it highlites "Next row_i". I have two "For" loops and two "next"s and have no idea why i am getting this error. Any help would be fantasitic. Thanks.


For row_i = 7 To last_i
Windows(ab).Activate
1_ab = Cells(row_i, 1)
2_ab = Cells(row_i, 2)
3_ab = Cells(row_i, 11)
4_ab = Cells(row_i, 7)

For row_j = 6 To last_j
Windows(ad).Activate
1_ad= Cells(row_i, 1)
2_ad = Cells(row_i, 2)
3_ad = Cells(row_i, 8)
4_ad = Cells(row_i, 6)

If 1_ab= 1_ad Then
If 2_ab = 2_ad Then
If 3_ab =3_ad Then
If 4_ab = 4_ad Then
GoTo NoError
Else
If 4_ab <> 4_ad Then
''''' report error''''''
Windows(myname).Activate
Sheets("4 mismatch").Select
Cells(error_count + 8, 1).Value = row_i
Cells(error_count + 8, 2).Value = 2_ab
Cells(error_count + 8, 3).Value = 4_ab Cells(error_count + 8, 4).Value = 4_ad
error_count = error_count + 1
error_count_absolute = error_count_asolute + 1
End If
End If
End If
End If
End If
Next row_j
If row_i = last_i Then
files_count = files_count + 1
Cells(error_count_absolute + 10, 1).Value = "File"
End If
If files_count > 1 Then
error_count = error_count_absolute
NoError:
Next row_i

mdmackillop
02-14-2011, 11:10 AM
You are missing an "End If" in here

If files_count > 1 Then
error_count = error_count_absolute
NoError:
Next row_i



Try Smart Indent (see my sig)

dub
02-14-2011, 11:17 AM
Ha! my bad, the "Next without For" threw me off. Thanks!