我有一個相當複雜的For
循環與If
聲明裏面和另一個For
循環裏面。並給予一定的標準(即If InStr(1, q.Value, "Total")
)在第二秒內我想結束整個If
聲明並轉移到Next C
。結束如果/下一個C語句與For循環/ VBA
我明白,這是像洋蔥一樣分層,可能不是一個簡單的出路。
For Each C In copyRng
If IsNumeric(C) And C.Value <> "0" And Len(C) <> 0 And C.Value <> "2017" Then
Set rowRange = xSheet.Range(C, C.EntireColumn.Cells(1)) 'set range from cell up to the top cell of the comment/ Fix the 2017 thing
For Each q In rowRange 'Loop through that range and find the Account number just above it and set it as rowSrc
If InStr(1, q.Value, "C-") And Not ISIN(C, uniqueVal) Then Set rowSrc = q
If InStr(1, q.Value, "Total") Then End If 'At this point I want to leave the entire If Statement and move on to the next C
Next q
Set colSrc = C.EntireRow.Offset(0).Cells(1) 'find alert connected with the number
numCol = DestSh.Cells.Find(colSrc.Value, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column 'look for the column in which the same alert is listed
numRow = DestSh.Cells.Find(rowSrc.Value, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Row 'look for row in which the same account is listed
'Set destination
Set destRng = DestSh.Cells(numRow, numCol)
'Copy to destination Range
C.Copy destRng
End If
Next C
'If'語句不工作這樣。 If'Then..Then End If'實際上只是說'If ... Then:Do Nothing:End If',因爲'End If'只是'If'塊的最後一行。同樣,你的行'If ... Then _'也是有問題的,因爲那些是行連續標記。不要像那樣使用它們。它使你的代碼難以閱讀和調試。繼續下一個C的唯一方法是將你不想運行的代碼打包到if'If Not Instr()Then'的後面,然後,由於條件不滿足,下一個C將運行。 –
@BrandonBarney感謝您的幫助。我真的不確定If語句是如何工作的,現在它變得更有意義。 – ShieldData