简体   繁体   English

如果单元格包含特定文本,则复制整行 + 下一行

[英]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.

相关问题 如果单元格包含特定文本,则复制整行 - if cell contains specific text, copy whole row 如果单元格包含特定文本,请将整行和接下来的两行复制到excel 2013中的下一张工作表 - If a cell contains specific text, copy the whole row & the next two rows to next sheet in excel 2013 Excel - 如果单元格包含特定文本,则将整行移动到下一个工作表中 - Excel - move a whole row into the next worksheet if cell contains specific text 如果单元格包含特定值,则将某些数据复制到下一个可用行 - If a cell contains specific value copy certain data into next available row 如果单元格包含特定文本,则复制整列 - if cell contains specific text, copy whole column 如果单元格包含特定文本,则突出显示整行 - Highlighting entire row if cell contains specific text 搜索特定文本的行并将其复制到单元格 - Search Row for Specific Text and Copy it to Cell 如果同一行中的不同单元格包含文本,则将单元格复制到另一张工作表 - copy cell to another sheet if a different cell in the same row contains text Excel VBA如果单元格包含整个工作簿中的文本,则删除一行 - Excel vba Deleting a row if a cell contains a text throughout whole workbook 宏可在行中查找特定文本并复制到同一行中的单元格 - macro to find specific text in row and copy to cell in same row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM