vba 如果该行包含某个值,则将一行从一张纸复制到另一张纸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20269725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy a row from one sheet to another sheet if the row contains a certain value
提问by user3046457
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.
这不应该是复杂的代码,但我是 Excel VBA 的新手。我尝试了许多不同的方法,导致错误、无限循环和错误的选择。
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).
我需要逐行通过“Sheet1”一次选择一行,检查列 J 中的值是否正确(值 = 131125),如果是,则复制 - 将该行粘贴到“Sheet2”(到相同的行,就像在 Sheet1 中一样)。
Help is much appreciated! :)
非常感谢帮助!:)
采纳答案by Pankaj Jaju
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