问题
This shouldn't be complicated code, but I am new to Excel VBA. I've tried many different methods resulting in bugs, infinite loops, and wrong selections.
I need to go row by row through "Sheet1" selecting one row at a time, check if the value in Column J is correct (value = 131125), if it is then copy - paste the row to "Sheet2" (into the same row as it was in Sheet1).
Help is much appreciated! :)
回答1:
Sub Test()
For Each Cell In Sheets(1).Range("J:J")
If Cell.Value = "131125" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow).Select
Selection.Copy
Sheets("Sheet2").Select
ActiveSheet.Rows(matchRow).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End If
Next
End Sub
来源:https://stackoverflow.com/questions/20269725/copy-a-row-from-one-sheet-to-another-sheet-if-the-row-contains-a-certain-value