Consulting

Results 1 to 3 of 3

Thread: How to find exact substring within a cell

  1. #1

    How to find exact substring within a cell

    Hi All,

    I have a problem to find the exact match in cell.

    For example in cell A1: Johan sent an email

    when I am looking word "em" in cell A1 by using Instr function, the InStr function
    recognize the word "email". Problem is that search should match exact word 'em' not 'email'. How can I solve this?

    Thanks,
    Ramesh

  2. #2
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    One way to include 'em', but exclude 'email' is as follows:

    Sub dural()
        t = Range("A1").Text
        n = InStr(1, t, " em ")
        MsgBox n
    End Sub
    Have a Great Day!

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    msgbox instr(" "& cells(1,1).value &" ","em ")
    or

    msgbox not iserror(application.match("em",split(cells(1,1).Value),0))
    False 'em' not found
    True 'em' found

Posting Permissions

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