Phonebook application - Enhacing search capabilities

I have this phonebook application developed through this TA, the latest version at

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28645108.html

I have modified the data in this file and would like to enhance the search capability.

Currently the search looks for the string anywhere in the data field.

I would like to have a checkbox called "Whole words" which, when unchecked, works just as it does now.

When the checkbox is checked the search should look at whole words or numbers. So that ro would match Rory and not broomee. I think the delimeters for a word or number should be
space
comma
hyphen

There could be more but I think I can add that later.
PhonebookEEv5.0.xls
LVL 43
Saqib Husain, SyedEngineerAsked:
Who is Participating?
 
Robert SchuttSoftware EngineerCommented:
ro would match Rory and not broomee
I wouldn't call that a Whole word match but more a beginning of word match. Anyway, that's what I implemented using a regular expression. A small change (checking for another boundary at the end) would make it a Whole word match.

I think the delimeters for a word or number should be: space, comma, hyphen. There could be more but I think I can add that later.
There is a standard notation in regular expressions for word boundaries: \b. I haven't checked which characters that uses but in practice it has never let me down. In case you don't want to use it I left a comment in the code with an alternative.
PhonebookEEv5.1.xls
0
 
Saqib Husain, SyedEngineerAuthor Commented:
I wouldn't call that a Whole word match but more a beginning of word match

I agree but what I wanted was something short to write in there.

Thanks, looks good now.
0
 
Saqib Husain, SyedEngineerAuthor Commented:
HI, again, I just discovered that  the underscore is not considered a word separator. I cannot pick Chris_Bottomley  by typing B. Can you do something about it?
0
 
Robert SchuttSoftware EngineerCommented:
Yes sure, couple of options. In the userform code (line 19) you could specify "standard word boundary or underscore":
re.Pattern = "(\b|_)" & strInput ' "(^|[ ,_-])"

Open in new window


The comment there shows the alternative I mentioned earlier where you only allow the exact characters you want. Just make sure the "-" is the first or last character within the range (block quotes) because otherwise it changes the meaning to a range of characters.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.