+ Reply to Thread
Results 1 to 5 of 5

VLOOKUP to find state abbreviation in text and insert into a column

  1. #1
    Registered User
    Join Date
    01-22-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2007
    Posts
    2

    VLOOKUP to find state abbreviation in text and insert into a column

    I need to do the following...

    I have a column (B2:B60) of all the state abbreviations with a comma and space before them, ex.
    , AK
    , CT
    , WY

    I have another column that has mailing addresses with non-uniform formatting, ex. multiple commas, which will not allow me to split the state abbreviations into one column. The number of commas per address is never the same.

    I want to use Excel to reference the column with the state abbreviations to see if any of the abbreviations are in the column of addresses. If a match is found, I want it to insert the state abbreviation into another column.

    Ex. if Address in Cell A2 contains one of the state abbreviations in B2:B60, then insert the appropriate match from B2:B60 into cell C2.

    Any tips on how to do this, or an alternative method, would be much appreciated.

    Thanks!
    Attached Files Attached Files
    Last edited by Aferrara; 01-22-2011 at 07:05 AM. Reason: adjusted the cell numbers

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: VLOOKUP to find state abbreviation in text and insert into a column

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VLOOKUP to find state abbreviation in text and insert into a column

    You might try:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-22-2011
    Location
    Los Angeles, California
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: VLOOKUP to find state abbreviation in text and insert into a column

    Dave...thanks for the quick reply and the tips!

    Donkey, I tried your formula and it worked! Thanks so much. If possible, could you explain the logic behind each of the main elements in the formula?

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: VLOOKUP to find state abbreviation in text and insert into a column

    Essentially - from a work flow perspective:

    - a SEARCH is conducted for each term listed in B2:B60 against the value in A2 (note: A2 & B2 rather than A1 & B1 - row 1 can be ignored)

    - SEARCH will return a Number (found) or #VALUE! (not found)

    - LOOKUP in this instance will find the last number listed in our lookup_vector (search results) and return the associated value from our result vector (state list)
    LOOKUP works per the above because:

    - our criteria value is a VERY big number (9.99*10^307)

    - LOOKUP assumes all values in the lookup_vector are ascending order (irrespective of reality)

    - LOOKUP ignores values in the lookup_vector not of the same data type as our criteria (including errors)

    - LOOKUP retrieves the last value <= criteria from lookup_vector (or associated result_vector result where specified)
    Note:

    Given your examples you could try:

    Please Login or Register  to view this content.
    which would negate need for B2:B60 altogether.

    Also, when using this approach it's important to note that blanks in the lookup_vector would cause odd results - so a more robust method would be:

    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)

Tags for this Thread

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