I have a database of all 5000 cities to compare against. What I am trying to do is extract only the exact city names from a string. For example, let's say column A in Excel contains these phrases:
- bankruptcy new haven
- personal injury new york
- personal injury new york city
- injury new york city lawyer
In Column B, I would need the results to look like this:
- new haven
- new york
- new york city
- new york city
My logic would be something like:
If GEOS = InStr(strText, "new haven") Then
GEOS = "new haven"
elseif GEOS = InStr(strText, "new york") Then
GEOS = "new york"
elseif GEOS = InStr(strText, "new york city") Then
GEOS = "new york city"
End If
Yes, there will be a ton of if statements, which is necessary for this project. The problem with the above function, is that the results for column B look something like:
- new york
- new haven
- new haven
- new haven
The function isn't searching through the string looking for exact matches. It searches for any part of the string I am using as a comparison, and as long as any part of that string is matched to the target string, it wrongfully accepts it as a match. Is there any way to search through an array of strings to search for an exact match, using VBA?