0

I'm looking for a formula to search a pattern of LastName, FirstName, CompanyName in a cell, not in a group of cell but just in a single cell.

Example are as follows:
A1 Dollbert, John - Mainland Private Limited
A2 Jackson, Jennifer - Plastic Pty. Ltd.
A3 Fernando, Sammy - RTC Pty Ltd

I know some basics functions and some of the more advanced if functions and some basics of index, match functions, but that's just my limit for now.

I tried to lookup on Google how to accomplish this but no luck, and some are just for searching cell by cell per word, which is not what I need.

I have no formula for this yet as I've never really managed to accomplish this, all that I've tried are just not working or not even close.

Thank you in advance.

8
  • 5
    Can you better explain what you mean by search a pattern? You want to put a formula where, and what should it search for, and what should it do with the findings, etc. Commented Jun 7 at 3:45
  • Sorry I forgot to add that information, Search a pattern that is lastname, firstname, company name like the example above, and if it got a match it would simply output something like "Found".
    – Bryan
    Commented Jun 7 at 6:47
  • So there's some input somewhere, do you want it in a single cell? Or 3 seperate cells. Seeing your example, the data in 'summary' isn't always formatted the same?
    – Excellor
    Commented Jun 7 at 7:06
  • @Excellor No, there's no input, I forgot to add another cell there. And in that cell is where the formula. The formula is for the Summary, yes it's not always formatted the same and it will keep on changing, that's what I need the formula for, to know which summary is formatted correctly.
    – Bryan
    Commented Jun 7 at 7:18
  • Then how do you want to search something, if you don't know what to search for? Hence, some input.
    – Excellor
    Commented Jun 7 at 7:29

2 Answers 2

2

Excel cannot determine whether a string starts with last name, first name - company name however, it can determine the pattern if its constructed to find within a string.

What I have found from the context of the OP, and comments posted by OP, that it follows a certain pattern, and the pattern is like as below:

Last Name, First Name - Company Name


So, if we take the comma space and dash or hyphen space as the pattern between last name and first name and first name and company name, we can actually reach at a point of achieving the desired output.


enter image description here


• Formula used in cell E2

=LET(
     α, {", "," - "},
     AND(TEXTSPLIT(ClaimTbl[@Summary],
         TEXTSPLIT(ClaimTbl[@Summary],α),,1)=α))

  • First , split by the delimiters accounting here as the pattern check, using TEXTSPLIT() function
  • Then use again TEXTSPLIT() function to split data the actual data using the above.
  • Finally, compare it with the pattern to get TRUE and FALSE. I will explain and show in screenshots.

enter image description here


For reading and understandability one can write as :

=LET(
     _Delim, {", "," - "},
     _SplitByDelim, TEXTSPLIT(ClaimTbl[@Summary],_Delim),
     _SplitNotByDelim, TEXTSPLIT(ClaimTbl[@Summary],_SplitByDelim,,1),
     _Compare, AND(_SplitNotByDelim={", "," - "}),
     IF(_Compare, "FOUND","NA"))

CAVEAT: Again, to remind that the formula above doesn't determine whether the string starts with last name or first name or company, it only tries to find a specific pattern. Also it has been assumed that there will be comma between last name and first name, while a dash or hyphen will be between first name and company, usually it will stick to the pattern of Last Name, First Name - Company Name beyond any is not found.


1

To get the name: =LET(t,TRIM(TEXTSPLIT([@Summary],"-")),INDEX(SORTBY(t,ISERR(FIND(",",t))),,1))

To get the company: =LET(t,TRIM(TEXTSPLIT([@Summary],"-")),INDEX(SORTBY(t,ISERR(FIND(",",t))),,2))

The pattern being name and company being separated by - and the two separated strings being sorted by the string containing a , (the name) or not (the company), since your last example showed a different order than the others.

Or if you need the sur- and last names separated as well (you forgot to post expected results with sample data)

Surname : =LET(t,TRIM(TEXTSPLIT([@Summary],"-")), TEXTAFTER(@SORTBY(t,ISERR(FIND(",",t))),", "))

Last name: =LET(t,TRIM(TEXTSPLIT([@Summary],"-")), TEXTBEFORE(@SORTBY(t,ISERR(FIND(",",t))),","))

1
  • 1
    Oh when did you post this. Last night. Looks Good! Commented Jun 10 at 18:22

Not the answer you're looking for? Browse other questions tagged .