Find Specific Word in Text

How to find a specific word in a text string using the LIKE operator in a user defined function. The FindExactWordInString functions returns TRUE if a specific word is contained in a text string. You may think that this function is just another variation of Excel’s FIND or SEARCH functions or VBA’s Instr function. There’s an important difference. The FindExactWordInString function looks for a complete word. It can distinguish between ‘map’ and ‘mapped’, for example. The examples in the accompanying video clarify how our function works.

We have used the LIKE operator in our function which was originally shown by Excel MVP Rick Rothstein. The VBA Like operator allows us to compare strings against a pattern. We can also search a string to check if it contains another string, By searching if a string contains another string, Like does a similar job to the InStr string function. However, you’ll note that Like returns a TRUE or FALSE result whereas InSTR returns the starting position of the searched string in the text. Watch the video below:

Watch this video on YouTube.

Here’s the complete functions code:

Function FindExactWordInString(Text As String, Word As String) As Boolean
FindExactWordInString = ” ” & UCase(Text) & ” ” Like “[!A-Z]” & UCase(Word) & “[!A-Z]
End Function

Here’s the code for the INSTR function:

Sub positionofString()
Dim lposition As Long
lposition = InStr(1, Range(“A1”), “game”)
Range(“F1”).Value = lposition
End Sub

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

One thought on “Find Specific Word in Text”

  1. Hi Dr. Dinesh,

    I have been finding your videos useful for the past year.

    However i have been in search of a video where you developed a useform vba code that is able to search a range of data in a specific column and using partial information for example i’m trying to retrieve the details of this number 345678902678902349024, but would like the userform to search using the last 6 digits of this number then when i click “update” the information is edited in the database.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.