目前,我有一个宏,它在另一个文档中查找,如果存在值,则复制一个偏移量单元格。我已经有了下面的代码(只有选择/复制偏移单元格的部分),但它只复制一行。这对我正在搜索的大多数项目都很好。有人知道如何修改下面的代码来复制包含我搜索值的所有单元格吗?
For I = LBound(MyArr) To UBound(MyArr)
Set Rng = .Find(What:=MyArr(I), _
After:=.Cells(.Cells.Count), _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
'mark the cell in the column to the right if "Ron" is found
Rng.Offset(0, 4).Select
'Rng.Copy "A" & Rcount
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
Selection.Copy (Rng)
End If
Next I
End With
发布于 2013-04-01 15:36:49
我建议的是.Find方法的循环。
所以你有一个数据范围,也就是MyArr,想象它有50个项目长。您希望从0到50查找,直到找到您的项目。
假设你在位置8找到它,现在你再做一次搜索,但这次是从第9项到第50项,看看你是否找到了匹配的项。如果你没有,你就知道没有更多了。如果这样做,则重复上述操作,直到数组(范围)中的元素用完或没有更多的匹配。这有意义吗?
https://stackoverflow.com/questions/15744867
复制相似问题