+ Reply to Thread
Results 1 to 4 of 4

Find a specific string in a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Find a specific string in a cell

    Hi eveyone

    I have absolutely no idea how to get starting on this one. I've got a long string in cell B1.

    At some point there is the word "oms:SomeString," (without the quotes). I need to know whether SomeString is somewhere in the active sheet or not (the workbook running the VBA-code is not the active sheet)

    I can't just compare the cell B1 because it contains multiple words. Any hints are very welcome.

    Cheers,

    Jeroen
    Last edited by Jeroen1000; 10-12-2009 at 08:15 AM.

  2. #2
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Re: Find a specific string in a cell

    I've been doing some thinking. This piece of code searches for the string

      Cells.Find(What:="SomeStringl", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
    But I can't get it to return true of false. But it has given me more ideas on how to search the forums. I bet this question has been answered before.

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Find a specific string in a cell

    Hi

    Set a reference to the found cell and then check whether the found cell actually exists (ie whether the searched for term was found):

    Dim rFound As Range
    Set rFound = Nothing
    Set rFound = Activesheet.Cells.Find(What:="SomeStringl", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)       
    
    
    'note no .Activate on the end of the above statement!!
    
    'now check if the term was found:
    
    If Not rFound Is Nothing then   'if it isn't nothing then it's something ie it was found
      'search term found
    Else
      'term not found
    End If
    Make sense?

    Richard[/code]
    Richard Schollar
    Microsoft MVP - Excel

  4. #4
    Registered User
    Join Date
    09-21-2009
    Location
    Belgium
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    71

    Re: Find a specific string in a cell

    Brilliant mr. Schollar. I was toying with the idea but couldn't quite get it right. Thank you very much

+ Reply to Thread

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