[英]if cell contains specific text, copy whole row + next row
I am really new with VBS and need help.我对 VBS 很陌生,需要帮助。
I have sheet1 and sheet2.我有sheet1和sheet2。 All my raw data is in sheet1 column A and sheet2 will be summary report.
我所有的原始数据都在 sheet1 A 列中,而 sheet2 将是摘要报告。 I want my script to search each cell in column A and search for "Grade A".
我希望我的脚本搜索 A 列中的每个单元格并搜索“A 级”。 If find, copy entired row which contains Grade A word and also copy next row and paste it in sheet2.
如果找到,则复制包含 A 级单词的整行,并复制下一行并将其粘贴到 sheet2 中。 Here is an example.
这是一个例子。
Sheet1:表 1:
A B C
GradeA sdfasdf sadfsadf
Address sadfas sdfsadfs
Grade B sadfsd dgfdsgdf
Address sdfasf ertertewt
Grade C fhgfdgh ukjtyuyt
GradeA hhh lll
Address ppp hhh
Sheet2 shoud look like this after running script.运行脚本后,Sheet2 应该看起来像这样。
A B C
GradeA sdfasdf sadfsadf
Address sadfas sdfsadfs
GradeA hhh lll
Address ppp hhh
Thank you in advance.先感谢您。
Try the following code试试下面的代码
Sub Test()
For Each Cell In Sheets(1).Range("A:A")
If Cell.Value = "GradeA" Then
matchRow = Cell.Row
Rows(matchRow & ":" & matchRow + 1).Select
Selection.Copy
Sheets("Sheet2").Select
lastRow = ActiveSheet.UsedRange.Rows.Count
If lastRow > 1 Then lastRow = lastRow + 1
ActiveSheet.Range("A" & lastRow).Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.