Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Apr 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search Text in a Single Cell (VBA)

    Hi,
    I have an excel requirement. I am trying to write a macro, that would check the occurences of specific text within a single cell. If the text is found in that particular cell, then some more operations would be done. I am unable to
    1. Write a code, that would search a specific text / word within a single cell. Complexity increases as this cell may contain many other text entries that may not be relevant and are not required to be searched.
    2.If text is found then some other specific operations and if not...some other operations. Not sure if i something like this is possible

    y =text to be searched within a cell

    If activecell.find (y)=true then...
    ..do whatever
    Else
    ..do whatever
    End if

    Any help is appreciated.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Search Text in a Single Cell (VBA)

    You can use the InStr function. InStr(String1, String2) returns the position of the first occurrence of String2 in String1 if found, and 0 if not found.

    If InStr(ActiveCell.Value, y) > 0 Then

  3. #3
    Lounger
    Join Date
    Apr 2005
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Search Text in a Single Cell (VBA)

    Thanks Hans. I worked on it today and it works like a beauty.

Posting Permissions

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