+ Reply to Thread
Results 1 to 14 of 14

Formula to match State within a string of text and return the result

  1. #1
    Registered User
    Join Date
    07-24-2019
    Location
    Melbourne
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Formula to match State within a string of text and return the result

    Hi everybody,

    I have been trying to find a solution to this problem with no luck. I have wasted so many hours and don't know else to do but ask for help.

    In the file i have attached, I am trying to match the state (could be any one of NSW, VIC, WA, QLD, SA, TAS, ACT, NT) from the text within the url in column G and return the result in column C.

    Hopefully my explanation makes sense.

    Any help or assistance would be appreciated.

    Thanks,
    Futurefight
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Need help please with formula to match State within a string of text and return the re

    Would the state code always be between the 6th and 7th + symbol in the url or is that just the case in the attached sample data?

    BSB

  3. #3
    Registered User
    Join Date
    07-24-2019
    Location
    Melbourne
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Re: Need help please with formula to match State within a string of text and return the re

    Unfortunately not, it is just the case in the attached sample.
    Last edited by AliGW; 07-30-2019 at 01:42 AM. Reason: Please don't quote unnecessarily!

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Need help please with formula to match State within a string of text and return the re

    List the state codes in a column somewhere. For the sake of this example I've put them in cells M1:M8.
    Then use the below formula in C1 and copy down as required.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See attached.

    BSB
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    07-24-2019
    Location
    Melbourne
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Re: Need help please with formula to match State within a string of text and return the re

    Thank you for this. At first it looked to be working great but now I have noticed there is something wrong happening. Some data is present but it is returning #REF!
    and it also seems to be returning the wrong results but I cant work out exactly why, I have attached an updated example.

    For example, in the attached sample c6 is returning TAS when it should be QLD.

    Thanks,
    Futurefight
    Attached Files Attached Files

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,779

    Re: Need help please with formula to match State within a string of text and return the re

    I think your formula is wrong. Change it to this:

    =INDEX(M$1:M$8,SUMPRODUCT(ISNUMBER(SEARCH(M$1:M$8,G2))*ROW(M$1:M$8)))

    or whichever is the correct cell on the first row of data.

    Failing that, try this:

    =INDEX(M$1:M$8,SUMPRODUCT(ISNUMBER(SEARCH("+"&M$1:M$8&"+",K2))*ROW(M$1:M$8))) - K2 is based on your sample file attached

    Don't forget to enter using CTRL+SHIFT+ENTER.
    Last edited by AliGW; 07-30-2019 at 01:53 AM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Need help please with formula to match State within a string of text and return the re

    Ali is correct. Your CSV attachment shows my original formula but the data is in a different layout (i.e. there's a header row and the url is in a different column to your original file).

    If you correct everything to point in the right place it will work in most instances, however when you have urls that contain two of the possible codes then the formula falls over. i.e. in your second attachment they should all be QLD however if any of them contain the word 'Service' then they also contain 'VIC'. This is why the need for a more representative sample in the first place.

    Her second formula will solve that as it's looking for only instances of the state code with a + symbol directly before and after. However, there is no need to confirm it with Ctlr+Shift+Enter to make it an array formula as stated. The SUMPRODUCT element of it will handle that.

    On a separate note, if the details in your second attachment are not desensitized and contain real details of real people/companies, you may want to remove that attachment from the thread. K22 for example clearly shows a mobile phone number and putting data like that up on the internet for public consumption is probably not wise. It would more than likely break some data protection law, certainly here in the UK....

    BSB

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,779

    Re: Need help please with formula to match State within a string of text and return the re

    If you don't use CSE in my version of Excel (365 insider) you get a SPILL error. This latest version handles array formulae completely differently.

  9. #9
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Need help please with formula to match State within a string of text and return the re

    Aha! Well that makes sense. But I'm not using that version and from the bio details I'm not sure the OP is either

    BSB

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,779

    Re: Need help please with formula to match State within a string of text and return the re

    No, but I am just mentioning it for completeness. Going forward, more and more people reading this thread in the future will be using the latest version. Belt and braces!

  11. #11
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Need help please with formula to match State within a string of text and return the re

    Couldn't agree more!


    You may wish to have a look at my last point in post #7.


    BSB.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,779

    Re: Need help please with formula to match State within a string of text and return the re

    I did, but it's the OP's call. The data may or may not be sensitive.

  13. #13
    Registered User
    Join Date
    07-24-2019
    Location
    Melbourne
    MS-Off Ver
    MS Office 2016
    Posts
    4

    Re: Need help please with formula to match State within a string of text and return the re

    Thank you all again for your help, the solution was found in this formula suggested by AliGW:
    =INDEX(M$1:M$8,SUMPRODUCT(ISNUMBER(SEARCH("+"&M$1:M$8&"+",K2))*ROW(M$1:M$8)))

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,779

    Re: Formula to match State within a string of text and return the result

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Help with formula - pull state abbreviation out of string of text
    By algioia in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-10-2019, 01:14 PM
  2. Search and Match partial text string to full text and return a value
    By homa5424 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-09-2017, 10:52 AM
  3. Search for a match of a text within text string and return initial value
    By orehovka in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-23-2015, 06:48 AM
  4. Replies: 10
    Last Post: 09-18-2014, 09:36 AM
  5. [SOLVED] Return a result for the appearance of a text string in any cell in a row (EXCEL 2010)
    By Jonathan68 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-30-2014, 02:34 PM
  6. Search text string for range of text values - return match
    By crugg in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-03-2010, 09:55 AM
  7. [SOLVED] Return a text string when the result of VLOOKUP formula is #N/A
    By jeremy nickels in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-04-2006, 12: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