The VBA inst() (The instring command)
instr() command is useful in determining if a word or combination of characters exist in a text string. It returns 0 when it doesn’t find the string. If it does it returns the position of the start of the word or collection of characters.
Remember:
- It does so from left to right
- Use the instrrev() if you need right to left
- It must be an exact match – yes, it is case sensitive
instr(activecell.value, “fox”)
instr(activecell.value, “Fox”)
would return a value of 17. The “f” in fox is the 17th character in our string.
would return a value of 0 as the command is case sensitive.
The VBA Instrrev(The reverse instring Command)
If we arbitrarily modified our sentence and added a second fox:
“the quick brown fox jumped over the lazy fox dog.”
and wanted to find the last instance of our search word fox – reading right to left
instrrev(activecell.value, “fox”)
would return a value of 42. The “f” in last fox reading right to left is the 42nd character in our string.
If you enjoyed this post and video and would like to comment or share improvements please send your comments Here.
If you would like to say hello and buy me a cup of coffee Click here.

Raymond Mills, M.B.A., M.S. has spent over 20 years of his career as Accountant, Investment Bank and Credit Card Technical Auditor/ Data Analyst. His specialty was using Excel to get Big Databases including Teradata, Oracle, Squel Server and Sybase to give up their secrets.
Ray has said “I love nothing better than using VBA to unleash the power of Microsoft Office.” You can contact Ray @ 484 574-3190 or by emailing him Here
If you have a challenge with Excel, Access or Word and would like to speak with Ray, You can get his contact details by clicking here: Contact Me
Ray has said “I love nothing better than using VBA to unleash the power of Microsoft Office.” You can contact Ray @ 484 574-3190 or by emailing him Here
If you have a challenge with Excel, Access or Word and would like to speak with Ray, You can get his contact details by clicking here: Contact Me