For
ループの場合はかなり複雑ですが、If
ステートメントが内部にあり、もう1つがFor
ループ内にあります。そして、その2番目のForループの中に特定の基準(すなわち、If InStr(1, q.Value, "Total")
)が与えられたら、If
ステートメント全体を終了してNext C
に移動したいと思います。End If/Next Forループ/ VBAを使用したCステートメント
私はこれがタマネギのように重なっていることを理解しています。簡単な方法がないかもしれません。
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 End If'は本当に' If ... Then:Do Nothing:End If'を 'End If'から' If'ブロックの最後の行だけと言っています。同様に、 'If ... Then _'という行は、行継続トークンであるため、問題があります。そのようなものは使わないでください。コードの読み込みやデバッグが難しくなります。次のCへ進む唯一の方法は、 'If Not Instr()Then'の逆に実行したくないコードをラップすることです。条件が満たされないので、次のCが実行されます。 –
@BrandonBarneyは助けてくれてありがとう。私は本当にIfステートメントがどのように機能していたのかよく分かりませんでした。 – ShieldData