UDF to remove stop words is not removing all words in my array

danalyst

New Member
Joined
Aug 14, 2015
Messages
2
Hi. I'm new to VBA, using excel 2003 (yes, I know....that's what company gave me) and trying to create a UDF to strip "stop words" from addresses. The udf works but for some reason not all words are being replaced? For example " Avenue " is not being replaced from string "199 Lee Avenue PMB 873". Replaces some words not others. could there be something in my data? I trimmed the strings.
1. is there a way to remove stop words that are at the end of the string, within the same udf?
2. is there a way to find/replace regardless of case, not have to include in my array all combinations " apt ", " Apt ", " APT "
Thank you.

Function RemoveAddrWordsV2(sInput As String) As String
Dim arr, I

arr = Array(" apartment ", " Apartment ", " Apartment ", " apt ", " Apt ", " APT ", " apmt ", " Apmt ", " APMT ", _
" ave ", " Ave ", " AVE ", " avenue ", " Avenue ", " AVENUE ", " bdlg ", " Bdlg ", " BDLG ", " blvd ", _
" BLVD ", " Blvd ", " boulevard ", " Boulevard ", " BOULEVARD ", _
" building ", " Building ", " BUILDING ", " court ", " Court ", " COURT ", " ct ", " Ct ", " CT ", _
" e ", " E ", " east ", " East ", " EAST ", " expressway ", " Expressway ", " EXPRESSWAY ", _
" expy ", " Expy ", " EXPY ", " expw ", " Expw ", " EXPW ", " floor ", " Floor ", " FLOOR ", " fl ", " Fl ", " FL ", _
" highway ", " Highway ", " HIGHWAY ", " highwy ", " Highwy ", " HIGHWY ", " hiway ", " Hiway ", " HIWAY ", _
" hiwy ", " Hiwy ", " HIWY ", " hway ", " Hway ", " HWAY ", " hwy ", " Hwy ", " HWY ", _
" Lane ", " lane ", " LANE ", " Ln ", " LN ", _
" n ", " N ", " north ", " North ", " NORTH ", " ne ", " Ne ", " NE ", " northeast ", " Northeast ", " NORTHEAST ", _
" nw ", " Nw ", " NW ", " northwest ", " Northwest ", " NORTHWEST ", _
" s ", " S ", " se ", " SE ", " Se ", " south ", " South ", " SOUTH ", " southeast ", " Southeast ", " SOUTHEAST ", _
" sw ", " SW ", " Sw ", " southwest ", " Southwest ", " SOUTHWEST ", _
" room ", " Room ", " ROOM ", " rm ", " Rm ", " RM ", " route ", " Route ", " ROUTE ", " rte ", " Rte ", " RTE ", _
" Road ", " road ", " ROAD ", " Rd ", " RD ", " sq ", " SQ ", " sqr ", " Sqr ", " SQR ", " sqre ", " Sqre ", " SQRE ", " squ ", " Squ ", " SQU ", _
" square ", " Square ", " SQUARE ", " st ", " St ", " ST ", " ste ", " Ste ", " STE ", _
" str ", " Str ", " STR ", " street ", " Street ", " STREET ", " strt ", " Strt ", " STRT ", _
" suite ", " Suite ", " SUITE ", " unit ", " Unit ", " UNIT ", " w ", " W ", " west ", " West ", " WEST ", _
" unit ", " Unit ", " UNIT ", " parkway ", " Parkway ", " PARKWAY ", " parkwy ", " Parkwy ", " PARKWY ", _
" pkway ", " Pkway ", " PKWAY ", " pkwy ", " Pkwy ", " PKWY ", " pky ", " Pky ", " PKY ", _
" pl ", " Pl ", " PL ", " place ", " Place ", " PLACE ")


For I = LBound(arr) To UBound(arr) Step 2
sInput = Replace(sInput, arr(I), " ")
Next I


RemoveAddrWordsV2 = sInput



End Function
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Thanks mjbeam but sinput was all converted to lcase.
543 Bedford Ave PMB 23289
was converted to:
543 bedford pmb 23289

I need to retain the original case.

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,857
Messages
6,127,372
Members
449,381
Latest member
Aircuart

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top