
vba 中findnext怎样才能嵌套使用?
展开全部
findnext的使用条件:搜索的 单元格区域、内容、其他设置 都与前面的find相同
例如:
Public Sub iFind()
Dim c As Range, rng As Range, s$, iAdd$, msg$, n&
Set rng = Range("A:A")
s = "abc"
With rng
Set c = .Find(s, .Cells(.Cells.Count), xlValues, xlWhole)
If Not c Is Nothing Then
iAdd = c.Address(0, 0)
Do
n = n + 1
msg = msg & vbCrLf & c.Address(0, 0)
Set c = .FindNext(c) '条件不变,使用FindNext
If c Is Nothing Then Exit Do
Loop Until iAdd = c.Address(0, 0)
End If
End With
MsgBox "完成!共找到 " & n & " 个“" & s & "”:" & vbCrLf & msg
End Sub
例如:
Public Sub iFind()
Dim c As Range, rng As Range, s$, iAdd$, msg$, n&
Set rng = Range("A:A")
s = "abc"
With rng
Set c = .Find(s, .Cells(.Cells.Count), xlValues, xlWhole)
If Not c Is Nothing Then
iAdd = c.Address(0, 0)
Do
n = n + 1
msg = msg & vbCrLf & c.Address(0, 0)
Set c = .FindNext(c) '条件不变,使用FindNext
If c Is Nothing Then Exit Do
Loop Until iAdd = c.Address(0, 0)
End If
End With
MsgBox "完成!共找到 " & n & " 个“" & s & "”:" & vbCrLf & msg
End Sub
追问
问题没有描述清楚。
2个findnext如何嵌套使用。
谢谢!
find(a)
find(b)
findnext(b)
findnext(a)
追答
findnext是根据前一个find或findnext来的,嵌套不了
相当于 复制和粘贴,复制一次,后面一直可以粘贴,但是只能有一次复制,不能嵌套
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |