Results 1 to 5 of 5

VBA Find() question

Threaded View

  1. #1
    Registered User
    Join Date
    04-14-2009
    Location
    Arkansas, USA
    MS-Off Ver
    Excel 2007
    Posts
    6

    VBA Find() question

    I'm trying to use the find function to make my macros easier to handle, but I don't know how to run through all instances of what I'm trying to find and then stop. Currently I just have my find function in an infinite loop and it stops when it runs into an error. This works well I guess, but I'd like to know how to stop after the last instance without error. Here's the code that I have been using:

    Do
        Cells.Find(What:="(", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False).Activate
    
        'Unimportant code here
    
    Loop
    I've done some searches and found some code that checks to see if the find function returns a range. I've tried this method, but because I know nothing about this language, I'm having a hard time figuring out where my code is messing up. Here's the code that I'm trying to code now:

    Dim rFound As Range
    Do
        Set rFound = Cells.Find(What:="(", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
            xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=False).Activate
        If Not rFound Is Nothing Then
            'Unimportant code here
        End If
    Loop While Not rFound Is Nothing
    The code I'm replacing with "'Unimportant code here" has been tested and works fine. The program runs into an error at "Set rFound = ...". Does anybody know what I'm doing wrong?

    --dorky
    Last edited by dorkydude666; 04-20-2009 at 01:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1