Is there a way to trim the parameters of a search using Find
prior to the search?
I have an Excel file that I would like to search through to find a cell with a particular word in it; each cell contains only one word. The Find
function is case-insensitive and works perfectly for the most part. The only (possible) flaw that I have found is that the cell must contain ONLY the word without leading and trailing spaces.
For example:
If I want to search for the word acoustic using the Find
function
Dim rng as Range
rng = ActiveSheet.Range("A1:K100")
Set foundItem = rng.Find("acoustic")
if not foundItem Is Nothing Then MsgBox foundItem.Address
This will find the word in its many variations - "Acoustic", "aCOUstic", "acouSTic", etc. but will NOT find it if it has a leading or trailing space, such as " acoustic" or "acoustic ".
So, is there a way to (easily) trim the spaces off the cell prior to performing the search? Or will I have to create a function to go through the range and trim first?