[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2354
  • Last Modified:

Excel VBA FindNext Error

Hi

I am using the following VBA code to find all instances of a value in a spreadsheet.
The first Find works but the code falls over on the FindNext part that I have marked with #####

    Dim c As Range
    Dim firstAddress As String
    With Worksheets(oSheetName)
     
        Set c = Cells.Find(What:=oWhat, After:=Range("A1"), LookIn:=oLookin, LookAt:= _
        oLookat, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False)
        Call ActionCellContent3(c.Address)
       
        If Not c Is Nothing Then
            firstAddress = c.Address
            Do
                Set c = .FindNext(c) '########
   
                Call ActionCellContent3(c.Address)
            Loop While Not c Is Nothing And c.Address <> firstAddress
        End If
    End With
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
Chris BottomleyCommented:
Hi

'Mr Microsoft' recommends replacing the findnext with a duplicate of the find command BUT adding to it the "after:=activecell, " option.  This has worked for me.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now