Reputation: 359
I have the following issue. I have several source file to copy from into my summary sheet (the order of columns/rows can differ). Thus, I am trying to do some hard-coded check with a h/v-lookup combo. The code is the following:
For i = 2 To Row_number
'''' 1150 ''''
If (Cells(i, 42).Value = "1150") Then
If (WB_1150 Is Nothing) Then
Set WB_1150 = Workbooks.Open(directory & file_1150)
For Each wb In Workbooks
If (wb <> ThisWorkbook & wb <> WB_1150) Then
wb.Close savechanges = False
End If
Next wb
End If
bool_vlookup_result = IsError(Application.vlookup(ThisWorkbook.Sheets(sheet_name_swaption).Cells(i, 12), WB_1150.Sheets(1).range("V1:V" & Row_number), 1, False))
If (bool_vlookup_result = True) Then
ThisWorkbook.Activate
Sheets(sheet_name_swaption).Activate
Cells(i, 43).Value = "ERROR"
Next i
Else
row_index_result = Application.Match(Cells(i, 2), WB_1150.Sheets(1).range("V1:V" & Row_number), 0)
For j = 1 To 42
If (Cells(row_index_result, j) = "") Then
Next j
Else
bool_hlookup_result = IsError(Application.HLookup(ThisWorkbook.Sheets(sheet_name_swaption).Cells(i, j), WB_1150.Sheets(1).range(Cells(row_index_result, 1), Cells(row_index_result, 22)), 1, False))
If (bool_hlookup_result = True) Then
ThisWorkbook.Activate
Sheets(sheet_name_swaption).Activate
Cells(i, 43).Value = "ERROR"
Next i
End If
End If
Next j
ThisWorkbook.Activate
Sheets(sheet_name_swaption).Activate
Cells(i, 43).Value = "OK"
End If
End If
'''' End 1150 ''''
''' OTHER SOURCE FILES '''
Next i
I get the error Next without For, because as soon as I got an error I can skip to the following i/j. Any suggestions to solve/improve this? I know that there can be several ways to do those checks, but this is the most powerful (and most time-consuming though) instrument that I found. Many thanks in advance.
Upvotes: 0
Views: 1460
Reputation: 6463
You can do it in such way:
For i = 1 To 10
If i = 3 Then GoTo Cont
Debug.Print i
Cont:
Next i
Upvotes: 1