简体   繁体   English

查找某些文本,复制并粘贴到新工作表中

[英]Find certain text, copy and paste into new sheet

I have this code here that goes through my sheet column C and and find all the cells with "Geoff" in it and copies it and pastes it in "Geoff" sheet from active sheet. 我在这里的代码遍历我的工作表列C,找到了所有带有“ Geoff”的单元格,然后将其复制并粘贴到活动工作表的“ Geoff”表中。 what I need it to accomplish is copying the whole row and pasting it into "Geoff" sheet. 我需要完成的工作是复制整行并将其粘贴到“ Geoff”工作表中。

Dim K As Long, r As Range, v As Variant
K = 1
Dim w1 As Worksheet, w2 As Worksheet
Set w1 = Sheets("Active")
Set w2 = Sheets("Geoff")
w1.Activate
For Each r In Intersect(Range("C:C"), ActiveSheet.UsedRange)
    v = r.Value
    If InStr(v, "Geoff") > 0 Then
        r.Copy w2.Cells(K, 1)
        K = K + 1
    End If
Next r

it only copies Geoff from Column CI need it to copy the entire row. 它仅从列CI复制Geoff,需要它复制整个行。 Any help or ideas? 有什么帮助或想法吗?

r.EntireRow.Copy w2.Cells(K, 1)

should work 应该管用

Or if you want to be more selective: 或者,如果您想更具选择性:

r.EntireRow.Cells(1).Resize(1, numColsToCopy).Copy w2.Cells(K, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM