使用工作表1中的值,search工作表2,并将工作表中的值作为工作表3返回

这个问题我在第2页有一堆数据。大约有6k行。 我有一些437我想find。 这些在表1(A栏)中有规定。 对于这些我想复制整个行,并将其放置在工作表3中。工作表1中的值可以在工作表2中多次find,我需要他们。

我的解决scheme,我发现VBAsearch这一切。 但是在437点停止。

Public Sub findfak() Dim lastRowS1 As Long Dim lastRowS2 As Long Dim lastRowS5 As Long Dim i As Long Dim j As Long Dim tempS1 As Long Dim temps2 As Long Dim tempRow As Long lastRowS1 = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row lastRowS2 = Sheet2.Cells(Rows.Count, 1).End(xlUp).Row Application.ScreenUpdating = False For i = 2 To lastRowS1 tempS1 = Sheet1.Cells(i, 1).Value If Not IsError(Application.Match(tempS1, Sheet2.Range("A:A"), 0)) Then lastRowS5 = Sheet5.Cells(Rows.Count, 1).End(xlUp).Row Sheet2.Rows(i).EntireRow.Copy Destination:=Sheet5.Rows(lastRowS5 + 1) End If Next i Application.ScreenUpdating = True End Sub 

尝试这个。

 Sub findfak() Dim lastRowS1 As Long Dim lastRowS2 As Long Dim lastRowS5 As Long Dim i As Long Dim j As Long Dim tempS1 As Variant Dim temps2 As Long Dim tempRow As Long Dim ws1 As Worksheet Dim ws2 As Worksheet Dim ws3 As Worksheet 'change sheets as necessary Set ws1 = WorkSheets("Sheet5") Set ws2 = WorkSheets("Sheet6") Set ws3 = WorkSheets("Sheet2") lastRowS1 = ws1.Cells(Rows.Count, 1).End(xlUp).Row lastRowS2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row Application.ScreenUpdating = False For i = 2 To lastRowS1 tempS1 = ws1.Cells(i, 1).Value For j = 2 To lastRowS2 If ws2.Cells(j, 1) = tempS1 Then lastRowS5 = ws3.Cells(Rows.Count, 1).End(xlUp).Row ws2.Rows(j).EntireRow.Copy Destination:=ws3.Rows(lastRowS5 + 1) End If Next j Next i Application.ScreenUpdating = True End Sub