我想讓Excel查看兩個不同的工作表中的兩個不同的行,但同一列來驗證在單獨的列中移動的數字。 我該如何擺脫我擁有的當前循環,以便減少加載時間?因爲截至目前還需要太長長。 另外,我知道我不應該用循環來,我用它在低希望,這是可行的,就像細檢查兩個不同的行,但同一列
Sub repeatingrows()
Dim oldsheet As Worksheet
Dim newsheet As Worksheet
Set newsheet = Application.ActiveSheet
Set oldsheet = ThisWorkbook.Worksheets(3)
Set newsheet = ThisWorkbook.Worksheets(2)
'CHECK IF THE ROWS ARE SIMILAIR TO PREVIOUS SHEET
Dim rrow As Integer
Dim srow As Integer
For rrow = 3 To 397
For srow = 3 To 397
If oldsheet.Cells(rrow, 2) = newsheet.Cells(srow, 2) Then
If oldsheet.Cells(rrow, 5) = newsheet.Cells(srow, 5) Then
If oldsheet.Cells(rrow, 6) = newsheet.Cells(srow, 6) Then
With newsheet
oldsheet.Range(oldsheet.Cells(rrow, 16), oldsheet.Cells(rrow, 19)).Copy
.Range(.Cells(srow, 16), .Cells(srow, 19)).PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd
End With '^COPY AND PASTES THE ROW
Else
End If
Else
End If
Else
End If
Next srow
Next rrow
End Sub
使用'worksheetfunction.match'或數組進行比較。 –
而不是使用嵌套的'if',你可以使用'And'運算符將所有語句組合成一個。 –
@Nathan_Sav是,而不是循環和ifs或只是如果的? – MaxAttack102