Excel 如何使用.FindNext查找范围内的值?

Excel 如何使用.FindNext查找范围内的值?,excel,vba,Excel,Vba,我需要找到A1:A14范围内值为“b”的单元格。该范围内有三个这样的值。 如果找到值,则将B2设置为“是”,然后在下面偏移一行 在这段代码中,我编写了findNext函数不起作用 Sub sinep() Dim sinepRng As Range Dim rangeRover As Range Set rangeRover = Range("B2") Set sinepRng = Range("A1:A14").Find("b",

我需要找到A1:A14范围内值为“b”的单元格。该范围内有三个这样的值。
如果找到值,则将B2设置为“是”,然后在下面偏移一行

在这段代码中,我编写了
findNext
函数不起作用

Sub sinep()

Dim sinepRng As Range
Dim rangeRover As Range

Set rangeRover = Range("B2")
Set sinepRng = Range("A1:A14").Find("b", LookIn:=xlValues)

If Not sinepRng Is Nothing Then
    firstAddress = sinepRng.Address
    MsgBox "first address " & firstAddress
    Do
    rangeRover.Value = "yes"
    Set rangeRover = rangeRover.Offset(1, 0)
    Set sinepRng = Range("A1:A14").Find("b").FindNext(sinepRng)
    MsgBox "third address " & sinepRng.Address
    If sinepRng Is Nothing Then
        MsgBox "isnothing"
        GoTo DoneFinding
        End If
    Loop While sinepRng.Address <> firstAddress
    End If
DoneFinding:
Sub sinep()
暗正弦范围
变暗rangeRover作为Range
设置rangeRover=Range(“B2”)
设置sinepRng=范围(“A1:A14”)。查找(“b”,查找:=xlValues)
如果不是,那么Sineprong什么都不是
firstAddress=sinepRng.Address
MsgBox“第一个地址”和第一个地址
做
rangeRover.Value=“是”
设置rangeRover=rangeRover.偏移(1,0)
设置sinepRng=范围(“A1:A14”).Find(“b”).FindNext(sinepRng)
MsgBox“第三地址”和sinepRng.地址
如果sinepRng什么都不是
MsgBox“什么都不是”
后进先出
如果结束
Sineprung.Address firstAddress时循环
如果结束
完成查找:
这个代码确实有效

Sub nag()

Dim rangeRover As Range
Set rangeRover = Range("B2")

With Worksheets(1).Range("a1:a500")
     Set c = .Find("b", LookIn:=xlValues)
     If Not c Is Nothing Then
        firstAddress = c.Address
        Do
            rangeRover.Value = "yes"
            Set rangeRover = rangeRover.Offset(1, 0)
            Set c = .FindNext(c)
        If c Is Nothing Then
            GoTo DoneFinding
        End If
        Loop While c.Address <> firstAddress
      End If
DoneFinding:
End With

End Sub
Sub-nag()
变暗rangeRover作为Range
设置rangeRover=Range(“B2”)
带工作表(1)。范围(“a1:a500”)
设置c=.Find(“b”,LookIn:=xlValues)
如果不是,那么c什么都不是
firstAddress=c.地址
做
rangeRover.Value=“是”
设置rangeRover=rangeRover.偏移(1,0)
集合c=.FindNext(c)
如果c什么都不是
后进先出
如果结束
在c.AddressFirstAddress时循环
如果结束
完成查找:
以
端接头

我认为问题出在
findNext
中。我试图修改它,但没有成功。我还尝试将
Find
与After参数一起使用。

感谢@Rory提供的解决方案


我不得不从
Set sinepRng=Range(“A1:A14”).find(“b”).FindNext(sinepRng)
Set sinepRng=Range(“A1:A14”).find(“b”)
行中删除
。FindNext(sinepRng)
看起来很可疑。删除该行的
.find(“b”)
部分。@Rory谢谢,完成了!我不知道为什么我认为我需要重述这句话。