我是 VBA 的新手。我正在尝试在 Sheet1 中查找一些数据并将其复制到 Sheet2。当我从 Sheet1 中选择数据时,我需要将其附加到 Sheet2 中已有的数据中。
我可以使用以下代码查找并粘贴数据,但无法附加。我的代码做错了什么?
Sub Copy_To_Another_Sheet_1()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim i As Long
Dim NewSh As Worksheet
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
MyArr = Array("37", "283", "300", "112", "1100", "336", "98")
Set NewSh = Sheets("Sheet2")
With Sheets("Sheet1").Range("B5:B500")
Rcount = 0
For i = LBound(MyArr) To UBound(MyArr)
Set Rng = .Find(What:=MyArr(i), _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
Rng.EntireRow.Copy NewSh.Range("A" & Rcount)
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
End If
Next i
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub