这是我用于excel电子表格和#34;产品数据库"的代码。它工作正常,我只需要它继续"循环"在某种方式。在我搜索我正在寻找的产品之后是消息框,它将其复制并粘贴到另一个工作表上并且它会向下移动一行。然后当我再次搜索时,它会删除我之前搜索过的内容。
这是代码:
Sub Test2()
Dim myWord$
myWord = InputBox("What key word to copy rows", "Enter your word")
If myWord = "" Then Exit Sub
Application.ScreenUpdating = False
Dim xRow&, NextRow&, LastRow&
NextRow = 2
LastRow = Cells.Find(what:="*", After:=Range("A1"), SearchORder:=xlByRows,
SearchDirection:=xlPrevious).Row
For xRow = 1 To LastRow
If WorksheetFunction.CountIf(Rows(xRow), "*" & myWord & "*") > 0 Then
Rows(xRow).Copy Sheets("Heather").Rows(NextRow)
NextRow = NextRow + 1
End If
Next xRow
Application.ScreenUpdating = True
MsgBox "Macro is complete, " & NextRow - 2 & " rows containing" & vbCrLf & _
"''" & myWord & "''" & " were copied to Heather.", 64, "Done"
End Sub
答案 0 :(得分:0)
你已经宣布public signal
每次从2开始计算。
使用吹码 -
NextRow = 2
但是,您可以根据需要更改列(A)。