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

1. ## 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

2. ## 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)

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

What if they're not all the same length?

4. ## 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

5. ## 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. ## 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.

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

#### 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