Consulting

Results 1 to 7 of 7

Thread: Solved: Find / FindNext question

  1. #1

    Solved: Find / FindNext question

    Hi,

    I'm trying to find all cells in Column A that are formatted Bold and Underlined.
    The macro in the attachment should do exactly that.
    A far as I know, it should find cell A4, then at FindNext, wrap around and exit the loop.
    Instead, at Find method it finds A4, and at successive FindNext methods it keeps finding A16, A1, A2, A16, A1, A2, and so on, in an infinite loop. It never even gets back to A4! Not to mention that A1, A2 and A16 don't have the format that was specified to look for.

    I'm looking for an explanation, why is that so.

    EDIT ON
    Please note: This problem didn't stop me from writing the code I wanted, because I have found a workaround (which was kindly shared below, by Andy Pope), so it's not an issue. I'm looking for answer to the question above.
    EDIT OFF

    Thanks,

    Jimmy
    Last edited by JimmyTheHand; 01-03-2007 at 03:00 AM.
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Hi,

    Not exactly sure why but the .findnext seems to be causing the problem.
    Try this modification.
    [vba]Sub Extract()
    Dim Src As Worksheet
    Dim FirstAddress As String
    Dim c As Range

    With Application.FindFormat.Font
    .FontStyle = "Bold"
    .Underline = xlUnderlineStyleSingle
    End With

    For Each Src In ThisWorkbook.Sheets
    With Src.Range("A:A")
    Set c = .Find(What:="", LookIn:=xlFormulas, lookat:=xlPart, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=True)
    If Not c Is Nothing Then
    FirstAddress = c.Address
    Do
    'do something here
    Set c = .Find(What:="", after:=c, LookIn:=xlFormulas, lookat:=xlPart, _
    SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=True)
    Loop While (Not c Is Nothing) And (c.Address <> FirstAddress)
    End If
    End With
    Next Src
    End Sub[/vba]
    Cheers
    Andy

  3. #3
    Hi Andy

    Thanks for your reply. I found exactly the same workaround.
    However, I'm looking for the answer to the question: what's the matter with FindNext. Sorry for not being specific enugh. I think I'll edit the first post.

    Best,

    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  4. #4
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Not much in the way of explanation but at least the problem is known.
    http://support.microsoft.com/kb/282151
    Cheers
    Andy

  5. #5
    Andy,

    thanks for the link. If M$ doesn't know, then who should. If they don't even make efforts to fix their product (the problem has been known since Excel 2002, and now, 5 years later, they release Excel 2007 with the same error... ), well, then I think that's the end of it.

    Problem "slved".

    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by JimmyTheHand
    thanks for the link. If M$ doesn't know, then who should. If they don't even make efforts to fix their product (the problem has been known since Excel 2002, and now, 5 years later, they release Excel 2007 with the same error... ), well, then I think that's the end of it.
    Come on now, you can't expect them to be adding new, 'necessary' functions and still bother about old problems!

  7. #7
    Quote Originally Posted by xld
    Come on now, you can't expect them to be adding new, 'necessary' functions and still bother about old problems!
    Sure. But if I expected them to neglect bugs and develop only new bells and whistles, and they actually lived up to my expectations, that would be equally frustrating
    Best is not to expect anything at all
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •