+ Reply to Thread
Results 1 to 21 of 21

How do I extract a 5 digit zip code from a column that may have a random number of text?

  1. #1
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    How do I extract a 5 digit zip code from a column that may have a random number of text?

    Hi all,

    I have a spread sheet with a column that includes a random amount of text like so:

    -----------------------


    Contact Name:


    Contact Email:


    Contact Phone:

    I am interested in 1234NE 12Tth, Williston, FL 32696.


    Search CriteriaCity :
    State :
    ZIP : 0
    MinLotSize : 0
    MaxLotSize : 0
    MinYearBuilt : 0
    MaxYearBuilt : 0
    PropertyTypes : CondoApartment, LotsLand, Manufactured, MultiFamily, SingleFamily

    -------------------

    What I want to do: Extract only the zip code from this column.
    My problem: I cannot find a formula to complete this task because every cell is different. Some may display the above posted or some may have double the text, so I am not sure how to pinpoint the formula to do what I want it to do.

    The words "I am interested in" appear in a majority of cells in the column, followed by the respective state, if that helps.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Assuming that your data is in column A and that the word "ZIP" is somewhere in that column, try the following macro:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    I am brand new with macros, so I am not entirely sure how to run this.

    I selected macros on the upper left, then created the macro by copying and pasting your code. Since the zip codes are in column D, I changed A to D instead. After I save the macro file, I am not too sure how to run and test it.

    I would ultimately want the zip codes inputted to a brand new column on the right.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,936

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Hi, welcome to the forum

    It would probably be a lot easier to help if you could upload a small (clean) sample workbook (not a pic) of what you are working with, and what your expected outcome would look like.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Thanks for the tip.

    So attached is a sample workbook of what I'll be working on. As you can see under the "notes" column, there is a body of text with the zip code. I want to be able to extract only the zip code shown to the row over to the right (column E)

    Thanks to everybody for the help so far.
    Attached Files Attached Files

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    I had a look at your file but I didn't see the word "ZIP" or any zip codes in column D. Do the following: Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the menu at the top click 'Insert' and then click 'Module'. Copy and paste the macro into the empty code window that opens up. Press the F5 key to run the macro. Close the code module window to return to your sheet. There are other quicker ways to run the macro such as assigning it to a button that you would click on your sheet or assigning it to a short cut key. Use this revised macro:
    Please Login or Register  to view this content.
    If it doesn't work the way you expect it, then please have another look at your file to make sure that the zip codes are included and re-post it.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    As both examples with zip codes relate to Florida, you could put this in E2:

    =IFERROR(MID(D2,FIND("FL",D2)+3,5),"")

    then copy down.

    Hope this helps.

    Pete

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    My apologies. Given the way that the data is organized, the macro I suggested won't work the way you want.

  9. #9
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Thank you for the help, I followed the instructions provided but it did not fill only the zip code in column E. Instead, it seems like it copied and pasted some text from column D to E.
    Attached Images Attached Images

  10. #10
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Hey, this worked! Thank you so much. So for different states, i would just have to replace "FL" with the correct one, right? Since the zip codes may be random, I would still need a useful macro to execute all zip codes, no matter the location.

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    There were only two examples (from three records) to work from. Both of them had FL followed by a space followed by the 5 digits that you wanted to extract. If you wanted something more generalised, you will need to submit another attachment which gives some more examples of the data that you have.

    Pete

  12. #12
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Hi Pete,

    Thanks for the reply. The rest of the data in the D column is in the same format with random, different states, as well as some extraneous notes that contain no numerical value.

  13. #13
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Okay, you can extend the formula like this:

    =IFERROR(MID(D2,FIND("FL",D2)+3,5),IFERROR(MID(D2,FIND("TX",D2)+3,5),IFERROR(MID(D2,FIND("MI",D2)+3,5),"")))

    and so on for other states that you deal with. It will bring the next 5 characters after the space following the appropriate state letters.

    Hope this helps.

    Pete
    Last edited by Pete_UK; 05-10-2016 at 05:27 PM.

  14. #14
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    For cells D3 and on, would I just have to replace the location with this and the state?

  15. #15
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    You would put the amended formula in cell E2, and then just copy it down as far as necessary.

    Pete

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Here's an UDF solution.
    Use in cell like
    =GetUSZipCode(D2)
    Please Login or Register  to view this content.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Pete,

    Thanks for all the help. When I copied and pasted that formula on my end, it produced an error, stating I would need to check my formula again.

    I believe we are on the right track to solution, so thanks again for all of your help.

  18. #18
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Sorry, I just spotted that I had left two = signs in the middle of the formula. I shall edit the previous post to show what it should be.

    Pete

  19. #19
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Much appreciated Pete. I'll look out for it.

  20. #20
    Registered User
    Join Date
    05-10-2016
    Location
    United States
    MS-Off Ver
    2013
    Posts
    12

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    Realistically, I will have to extend the formula for all other 47 states. In order to end the formula, would I still close it with the three outside parentheses?

    Edit: What I am asking is how would I close out the formula after 40+ states have been extended?
    Last edited by cmanlongat; 05-10-2016 at 05:50 PM.

  21. #21
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: How do I extract a 5 digit zip code from a column that may have a random number of tex

    That would make the formula very lengthy, and difficult to maintain. It would be better if you listed the state letters in a column (suppose this occupies cells I1 to I50), and then in E2 you could use this formula:

    =IFERROR(MID(D2,FIND(INDEX($I$1:$I$50,SUMPRODUCT(--(ISNUMBER(FIND(" "&$I$1:$I$50&" ",D2))),ROW($I$1:$I$50))),D2)+3,5),"")

    Note that I have put a space either side of the state letters in the inner Find function - this will avoid picking up on any words which contain any of the two-letter state abbreviations (like the word aNY).

    Copy this down column E as required.

    Hope this helps.

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 03-19-2016, 01:11 AM
  2. Replies: 6
    Last Post: 08-31-2015, 03:08 PM
  3. [SOLVED] 5-digit Random Unique Alphanumeric Code
    By mcodden in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-15-2015, 04:32 PM
  4. [SOLVED] 5-digit Random Unique Alphanumeric Code
    By mcodden in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2015, 02:39 PM
  5. [SOLVED] extract 10 digit number only from text string
    By visha_1984 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-06-2015, 09:42 AM
  6. [SOLVED] VBA to convert cell to text and ensuring 7 digit number all along in entire column.
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-19-2013, 09:35 AM
  7. Random 8 digit number?
    By KennyS in forum Excel General
    Replies: 6
    Last Post: 08-21-2006, 01:30 PM

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