我想保持外部循環後退出內部爲if語句,邏輯應該是正確的,但我不知道如何編碼它。我這樣做,它給了我一個「下一個沒有」的錯誤。想法?退出並保持循環上層的
這裏是我的代碼:
For InrCounter = 2 To InrNum
For ExrCounter = 2 To Exrnum
'add missing column data from input sheet to existing sheet
lastCofthisR = sheet1Table.Cells(ExrCounter, Columns.Count).End(xlToLeft).Column
'searching for address
If sheet1Table.Cells(InrCounter, 1) = sheet2Table.Cells(ExrCounter, 1) And sheet1Table.Cells(InrCounter, 2) = sheet2Table.Cells(ExrCounter, 2) And sheet1Table.Cells(InrCounter, 3) = sheet2Table.Cells(ExrCounter, 3) Then
If lastCofthisR < IncNum Then
For LastCofRowCounter = lastCofthisR + 1 To IncNum
Sheets("Sheet1").Cells(ExrCounter, LastCofRowCounter) = Sheets("Sheet2").Cells(InrCounter, LastCofRowCounter)
Next LastCofRowCounter
'found match loop next input row
Exit For
Next InrCounter
Else
'do nothing
End If
Else
Next ExrCounter
'do nothing
End If
'did not find the input row, find the last row of existing and add it
lrowEx = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For counterCofLastR = 1 To IncNum
Sheets("Sheet1").Cells(lrowEx + 1, counterCofLastR) = Sheets("Sheet2").UsedRange.Columns(1).Cells(InrCounter, counterCofLastR)
Next counterCofLastR
Next InrCounter
好吧,這意味着你錯過了下一個陳述。所以在頂部你必須爲陳述,但在底部你只關閉1,在應該循環的地方添加另一個陳述。 – Sorceri
在VBA中,您不得不求助於'GoTo'跳出內部循環到外部循環。 –
我把另一個聲明放在代碼的底部。我不知道如何在if語句中跳出內在的一面。 @Sorcei – user2600411