String Match part of an array with repeated strings in duplicate records and return value

Occasional Contributor


I have a dataset like below in Sheet3 as in the screenshot with ID, country and number where country column has 2 letter country codes as array of multiple countries together unique to a ID and number combination. You can also see that there are more than one record with the combination of ID and number due to local language name. 



In Sheet2, I have a 2 letter country code dropdown and a ID column, where when I select a country and against the ID, in the column H4 I should be able to fetch a number value from that dataset I mentioned earlier or just return multiple if the country exists in more than one combination. 





For that I have written the below formula in the column H4 using vlookup to find the country string in the helper column I created which is the concatenation of ID and country column string and cover the scenarios of the country existing in first place after the ID which is of fixed length or middle position or the last position to tell me if the country exists in one combination or in more than one. However, in a scenario like in the current dataset where the country "FI" or "SE" exists in more than one combination moreover in the same position due to which vlookup is returning the value for the first instance of the match rather it should say multiple. Is it possible to tweak my current formula to also include these scenarios or should I have to rethink of a new logic on the whole ?





This is works correctly if the country is not repeated or even if repeats but is in a different position. Like it does for "NO" country. See, below:





Chaitanya Palley

14 Replies



Does this formula return your expected result? Enter the formula with ctrl+shift+enter if you don't work with Office365 or 2021.



Hi @Quadruple_Pawn , thanks for the response. I used your formula, it still seems to work the same way as vlookup. It is bringing the first instance value when I select "FI". The formula should some way find that "FI" is more than once uniquely and let us to return "Multiple" as there are more than one number values for country "FI"(234 and 567). 




I assume that the formula is only entered in cell H4. You can drag the formula down to cell H10 and across the range H4:I10. In my sample sheet you can see that the formula returns all values for number and local language according to the country code and the ID.

@Quadruple_Pawn, Yes I only had the formula in one cell. However, even if I drag it is bringing me all the values into other cells where "FI" exists in the string. But what I am looking for is that in the same cells the formula should understand that there multiple values for that country and throw error which we can customize it to multiple. Is there a way I can use your formula and count the results in the background and do what I am looking for? 


Can you manually type your expected result in a spreadsheet and attach a picture of this to your reply?

best response confirmed by Chaitanya_Palley (Occasional Contributor)




This formula seems to work in my sheet. The formula has to be entered with ctrl+shift+enter if one doesn't work with Office365 or 2021. Do you happen to work with Office365 or 2021? I think with the help of the UNIQUE and FILTER formula it would be a lot easier to do this.



@Quadruple_Pawn, yes I am using office 365. 

Anyways, the formula seems to return true even if the country column does not have value resulting in returning value regardless of the country selection.



Actually in the expected results you didn't indicate that there is a scenario without a country code:

string match.JPG


If the formula should recognise scenarios without a country code one would have to add a NOT(ISBLANK(sheet4!G7)) statement in the formula.


However you work with Office365 and therefore i suggest to apply the new functions which extremely simplify task like this.

@Quadruple_Pawn, thanks so much for the formula, it works perfectly for my dataset which actually is where a huge dataset. Anyways, as you said, I used the blank condition for it to not return any value when country is not specified. 

Additionally before we close this topic, from the same formula, is it possible to return all the values  concatenated together in one cell when there are multiple values as the below screenshot:




You are welcome. With the same formula - which means without the Office365 functions such as TEXTJOIN, FILTER, UNIQUE - i have never seen or done a concatenation like this. Therefore I am glad that I can solve such tasks in Excel online.


@Quadruple_Pawn, from the formula, I tried only the below part to return all the values in one cell but it is only returning the first instance. How can tweak this to return all matching values in one cell without SPILL error so that I can concatenate them?




This formula works in my sheet.

@Quadruple_Pawn, thank so much!! This too works perfectly for me!! Thanks for all the help.