PDA

View Full Version : How to find exact substring within a cell



ramesh_sm81
07-04-2013, 10:14 AM
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

GarysStudent
08-25-2013, 06:46 AM
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

snb
08-25-2013, 09:05 AM
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