vba 基于单个单词、段落内、单元格内将整行从一张纸复制到另一张纸

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2630081/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:22:45  来源:igfitidea点击:

Copy an entire row from one sheet to another based upon a single word, within a paragraph, inside a cell

excelvba

提问by jason

I'm looking to copy a row from one sheet to another based upon having a specific word in the cell. I have a sheet one, called "data" and a sheet two called "final".

我希望根据单元格中的特定单词将一行从一张纸复制到另一张纸。我有一张名为“数据”的工作表和一张名为“最终”的第二张工作表。

Here is an example of the data

这是数据的示例

A         B            C               D  
john      mary         555.555.4939    initial reply to phone conversation  
Jim       Hyman         555.555.5555    floor estimate for bathroom  
jerry     kim          555.555.5553    initial response to phone call

I'd like to copy the entire row from sheet "data" to a sheet "final" if the data in column D contains either the word "reply" or the word "response".

如果 D 列中的数据包含“回复”或“响应”一词,我想将整行从“数据”表复制到“最终”表。

回答by Alex K.

This should work

这应该工作

Sub Foo()

Dim i As Long, iMatches As Long
Dim aTokens() As String: aTokens = Split("reply,response", ",")

For Each cell In Sheets("data").Range("D:D")

    If (Len(cell.Value) = 0) Then Exit For

    For i = 0 To UBound(aTokens)
        If InStr(1, cell.Value, aTokens(i), vbTextCompare) Then
            iMatches = (iMatches + 1)
            Sheets("data").Rows(cell.Row).Copy Sheets("final").Rows(iMatches)
        End If
    Next

Next

End Sub