所以我在" Sheet1"中有一个搜索按钮。搜索10,000个ID,当找到正确的ID时,它会将其粘贴到" Sheet2"中。我遇到的问题是我不知道如何重置按钮上的计数器。我希望能够搜索和粘贴4-5个ID,然后能够从" Sheet2"的顶部开始。再次,但现在它只是继续下降。我将附上我下面的代码。任何帮助将不胜感激。
Private Sub CommandButton1_Click()
Dim search_value As String
Dim loop_rows As Integer
Dim loop_i As Integer
Dim sheet_search As String
Dim sheet_paste As String
sheet_search = "Sheet1"
sheet_paste = "Sheet2"
search_value = TextBox1.Value
loop_rows = Sheets(sheet_search).UsedRange.Rows.Count
Sheets(sheet_search).Select
For loop_i = 1 To loop_rows
If Sheets(sheet_search).Cells(loop_i, 1) = search_value Then
Sheets(sheet_search).Rows(loop_i).Copy
Sheets(sheet_paste).Select
If IsNull(Sheets(sheet_paste).Cells(2, 1)) Then
Sheets(sheet_paste).Rows(2).Select
ActiveSheet.Paste
Else
' ActiveSheet.UsedRange.Rows(UBound (ActiveSheet.UsedRange.Value)).Row
Sheets(sheet_paste).Rows(Sheets(sheet_paste).UsedRange.Rows(UBound(ActiveSheet.UsedRange.Value)).Row + 1).Select
ActiveSheet.Paste
End If
End If
'loop_i = loop_i + 1
Next
End Sub
再次感谢