0
我想搜索文檔的E列中的特定字詞,並找到時複製它發現到另一個整行表單在同一個文檔中。下面的代碼能夠完成我想要做的事情,但它只是爲搜索的第一次出現而結束,並且我需要它繼續,直到找到所有事件並複製並粘貼。任何和所有的幫助將不勝感激。搜索特定字詞的1列,並找到將整行復制到另一個工作表
Sub Macro3()
Dim LSearchRow As Integer Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 2 LSearchRow = 2
'Start copying data to row 2 in Sheet2 (row counter variable) LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column E = "Aries Radio Control", copy entire row to Sheet2
If InStr(1, Range("E" & CStr(LSearchRow)).Value, "Aries Radio Control") > 0 Then
'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet ARC in next row
Sheets("ARC").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Sheet1 to continue searching
Sheets("sheet1").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3 Application.CutCopyMode = False Range("A3").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute: MsgBox "An error occurred."
End Sub