+ Reply to Thread
Results 1 to 7 of 7

Find and Replace Multiple Text String VBA

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Find and Replace Multiple Text String VBA

    In column C I have PO Box Addresses I need to normalize such as:

    P.O. Box 12345
    PO Box 12345
    P. O. Box 12345
    POB 12345
    box 12345
    BOX 12345

    I need to normalize the data by using find and replace

    Replace "P.O. Box " with "PO Box ", etc as example. Is there a way to find all combinations to replace in one statement without having to write multiple statements? The only requirement is it must not be case sensitive (i.e. strings "box " and "BOX " are the same)

    This is a partial list of replacements (I want to replace all with "PO BOX ")
    "P O Box "
    "POB "
    "BOX "
    "box "
    "Pob "
    "pob "
    "P.O. BOX "

    I have this so far:

    Please Login or Register  to view this content.
    Last edited by maacmaac; 12-28-2011 at 11:01 AM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Find and Replace Multiple Text String VBA

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Find and Replace Multiple Text String VBA

    Looks to me like your best bet would be to simply extract all the digits in the cells (eg 12345) and then replace the contents with your normalised string "PO Box" concatenated to the digits (this does of course assume your PO Box numbers are wholly composed of numeric characters):

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Find and Replace Multiple Text String VBA

    Is there a way to ignore "case" sensitive strings. For example for string "Box ", there are cases of BOX, Box, box, BOx, bOX, etc. I am trying to avoid having to write a case statetment for each possibility. thanks

  5. #5
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Find and Replace Multiple Text String VBA

    Assuming the Box numbers are all numeric then the code I posted should work

  6. #6
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Find and Replace Multiple Text String VBA

    Firefly,

    Thanks for code but it won't work as the file is composed of other addresses besides the Po boxes. I.e. there are other address types in same column such as 123 Smith Avenue. Thanks anyhow.

  7. #7
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: Find and Replace Multiple Text String VBA

    I was able to figure out a solution if multiple cases of upper/lower case combinations by using UCase solution.

    Replaced
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1