我有单元格L7,L12,L13,L14 上的值与下面的代码我可以找到值并收集到范围。但在.find循环函数搜索期间,再次到达第一个结果并退出.find函数。 问题是我收到范围L12,L13,L14,L7 通常L7必须在开始。Excel vba范围.find函数防止返回到第一个单元格
我该如何解决? 我可以阻止.find返回第一个单元格吗?或者我可以使用.find对我得到的范围进行排序吗?
Function FindAll1(rngLookIn As Range, LookFor) As Range
Dim rv As Range, c As Range, FirstAddress As String
With rngLookIn
Set c = .Find(LookFor, After:=Range("L2"), LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
FirstAddress = c.Address
Set rv = c
Do
Set c = .FindNext(c)
If Not c Is Nothing Then Set rv = Application.Union(rv, c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
End If
End With
Set FindAll1 = rv
End Function
这是我的代码调用函数
Set searchitem = FindAll1(arama, aranan)
If Not searchitem Is Nothing Then
For Each g In searchitem.Cells
我的代码从这里开始,但它配备L12的第一而不是L7从searchitem
它的工作原理感谢您的帮助! – Teo
不客气 – user3598756