[英]excel vba :why doesn't this nested for loop do 1 to multiple comparison?
[英]A Do until loop nested in a do while loop that doesn't compile in excel VBA
該代碼無法編譯,並在Do直到循環中顯示錯誤。 它說有一個循環,沒有執行。 這里有更多代碼,可以正常工作,並且模塊頂部有Option Explicit。 故障標記將2標記為最后一個循環。 我想念什么?
我試圖將代碼放在我嘗試過的單獨子中
intLastrowData = wbold.Worksheets(OldSheetName).Cells(Rows.Count, 1).End(xlUp).Row
intLastrowNew = WBnew.Worksheets(AktivtBlad).Cells(Rows.Count, 1).End(xlUp).Row
i = 3
Do While i <= intLastrowNew
strValueA = WBnew.Cells(i, intData1).Value
strValueB = WBnew.Cells(i, intData2).Value
j = 2
Do Until strValueA = wbold.Worksheets(OldSheetName).Cells(j, 1).Value
If Not wbold.Worksheets(OldSheetName).Cells(j, 1).Value = "" Then
If strValueA = wbold.Worksheets(OldSheetName).Cells(j, 1).Value Then
If strValueB = wbold.Worksheets(OldSheetName).Cells(j, 2).Value Then
wbold.Worksheets(OldSheetName).Range(Cells(j, 4), Cells(j, 18)).Copy
WBnew.Worksheets(AktivtBlad).Range(Cells(i, intData3)).Paste
Exit Do
End
End
End
j = j + 1
If intLastrowData > j - 2 Then
Exit Do
End
Loop
i = i + 1
Loop
我希望它可以將strValueA和strValueA與wbold.Worksheets(OldSheetName)中的數據進行比較,如果它匹配以從wbold復制數據並將其放入WBnew中,則將其匹配。 但是它不會編譯內部的Do直到Loop。
這很簡單: End If
,而不是End
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.