【发布时间】:2019-02-26 14:49:30
【问题描述】:
我有一个代码可以复制并粘贴一整行到名为“原始数据”的工作表中。如果范围 $D$1:D 中的单元格的值为“Thomas Xiong”,那么它将将该值下的所有内容的整行粘贴到另一个名为“WIP”的工作表中。
我想要做的是能够创建一个能够找到多个单词的代码。例如,“Thomas Xiong”和“Assigned”一词,并且能够将整行从工作表“Raw Data”复制并粘贴到另一个工作表中。
还有我现在拥有的代码,它会复制并粘贴整行,但另一个工作表中的每个单元格行之间都有空格。
我现在的代码:
Sub Test()
Dim Cell As Range
With Sheets("Raw Data")
' loop column C untill last cell with value (not entire column)
For Each Cell In .Range("D1:D" & .Cells(.Rows.Count, "D").End(xlUp).Row)
If Cell.Value = "Thomas Xiong" Then
' Copy>>Paste in 1-line (no need to use Select)
.Rows(Cell.Row).copy Destination:=Sheets("WIP").Rows(Cell.Row)
'.Range("C1:C", "A", "B", "D", "F" & Cell.Row).copy
End If
Next Cell
For Each Cell In .Range("C1:C" & .Cells(.Rows.Count, "C").End(xlUp).Row)
If Cell.Value = "Assigned" Then
' Copy>>Paste in 1-line (no need to use Select)
.Rows(Cell.Row).copy Destination:=Sheets("WIP").Rows(Cell.Row)
'.Range("C1:C", "A", "B", "D", "F" & Cell.Row).copy
End If
Next Cell
End With
End Sub
【问题讨论】: