+ Reply to Thread
Results 1 to 6 of 6

Searching a string to see if two parts of the string are equal

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    107

    Searching a string to see if two parts of the string are equal

    Hi,

    I'm trying to use a SUMIF function where I have two strings that are equal in the same cell. Example data:

    MI/IL | 10
    NY/NY | 3
    NY/MI | 7
    IL/IL | 6

    Ideal Output:

    Same State | 9

    There is another place in my data where I concatenate this data together, if that's any help to solving this. Any help would be much appreciated. Thanks
    Last edited by cheal2; 03-18-2013 at 09:58 AM.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Searching a string to see if two parts of the string are equal

    if they're all 2 character state codes
    =SUMPRODUCT(--(LEFT(A1:A4,2)=RIGHT(A1:A4,2)),B1:B4)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Searching a string to see if two parts of the string are equal

    What if they're not all the same length?

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Searching a string to see if two parts of the string are equal

    If your state pairs are in column A and the numbers are in column B, then in C1 enter:

    =IF(LEFT(A1,2)=RIGHT(A1,2),B1,0) and copy down

    Then use:

    =SUM(C:C)

    This solution assumes that the states are all two characters
    Gary's Student

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Searching a string to see if two parts of the string are equal

    then it's probably easier to test the source data but you can still do it if the / is always there as a delimiter
    =SUMPRODUCT(--(LEFT(A1:A4,FIND("/",A1:A4)-1)=MID(A1:A4,FIND("/",A1:A4)+1,LEN(A1:A4))),B1:B4)

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    Michigan
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Searching a string to see if two parts of the string are equal

    Thank you Joseph! I knew there had to be a way as long as that / is there.

+ 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