我试图将库存表中的行复制到水果工作表,但下面的代码会保留副本并粘贴在同一工作表中。我不知道如何改变这一点。有人能帮助我吗?提前感谢任何帮助!将基于多个标准的行从一个工作表复制到另一个VBA
Sub FruitBasket()
Dim rngCell As Range
Dim lngLstRow As Long
Dim strFruit() As String
Dim intFruitMax As Integer
intFruitMax = 3
ReDim strFruit(1 To intFruitMax)
strFruit(1) = "Fruit 2"
strFruit(2) = "Fruit 5"
strFruit(3) = "Fruit 18"
lngLstRow = ActiveSheet.UsedRange.Rows.Count
For Each rngCell In Range("A2:A" & lngLstRow)
For i = 1 To intFruitMax
If strFruit(i) = rngCell.Value Then
rngCell.EntireRow.Copy
Sheets("Inventory").Select
Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial xlPasteValues
Sheets("Fruit").Select
End If
Next i
Next
End Sub
为了增强一个美观的解决方案,应该在过滤之后对可见行进行检查。而且...按照OP的代码,'wsDest'应该设置为“Inventory”,'wsData'为“Fruit”... – user3598756
工作,感谢“评论清晰度” –
hello tigeravatar,在哪里放置警报消息:未找到,如果没有找到项目。谢谢 –