Excel - Forumla to seacrh for mutliple terms and show the matching term - excel

I have the challenge that I need to search in Excel for multiple terms and to get the result back for each cell which of the different terms has matched.
I know there is a formula combination to search for multiple terms but this will not give me the matched term back. The exampel below gives only a "0" or "1" back.
=IF(ISNUMBER(SEARCH({"TermA","TermB","TermC"},A1)),"1","0")
| | A | B |
| 1 | This is TermA | TermA |
| 2 | Some TermB Text | TermB |
| 3 | And TermA Text | TermA |
| 4 | another TermC | TermC |
Background I have to do some normalization of the values and look therefore for some forumla which can identify the values and list the match. The values which are used to search for should be later on another page so it can be easily extended.
Thank you for some hints and approaches which will put me into the right direction.

To return all matching terms:
=INDEX(FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[.='TermA' or .='TermB' or .='TermC']"),COLUMN(A1))
Wrap in an IFERROR() if no match is found at all.
If one has ExcelO365 and you refer to a range, things got a lot easier:
Formula in E1:
=TRANSPOSE(FILTER(C$1:C$3,ISNUMBER(FIND(C$1:C$3,A1))))

=INDEX(FILTER(C:C,C:C<>""),MATCH(1, COUNTIF(A1, "*"&FILTER(C:C,C:C<>"")&"*"), 0))
For use in office 365 version. If previous version replace FILTER(C:C,C:C<>"") with C$1:C$4 for your example or whatever your range of search values may be. Table reference is also possible.
The formula searches for the first match in your list of values if the text including your term contains a matching value anywhere in that text. It returns the first match.

Related

Excel: select the last number or numbers from a cell

Given the following examples,
16A6
ECCB15
I would only like to extract the last number or numbers from the string value. So the end result that I'm looking for is:
6
15
I've been trying to find a way, but can't seem to find the correct one.
Use thisformula:
=MID(A1,AGGREGATE(14,7,ROW($Z$1:INDEX($ZZ:$ZZ,LEN(A1)))/(NOT(ISNUMBER(--MID(A1,ROW($Z$1:INDEX($ZZ:$ZZ,LEN(A1))),1)))),1)+1,LEN(A1))
Try this:
=--RIGHT(A2,SUMPRODUCT(--ISNUMBER(--RIGHT(SUBSTITUTE(A2,"E",";"),ROW(INDIRECT("1:"&LEN(A2)))))))
or this (avoid using INDIRECT):
=--RIGHT(A2,SUMPRODUCT(--ISNUMBER(--RIGHT(SUBSTITUTE(A2,"E",";"),ROW($A$1:INDEX($A:$A,LEN(A2)))))))
Replace A2 in the above formula to suit your case.
Here are the data for testing:
| String |
|-----------|
| 16A6 |
| ECCB15 |
| BATT5A6 |
| 16 |
| A1B2C3E0 |
| 16E |
| TEST00004 |
I have an even shorter version: --RIGHT(A2,SUMPRODUCT(--ISNUMBER(--RIGHT(SUBSTITUTE(A2,"E",";"),ROW(INDIRECT("1:"&LEN(A2)))))))
The difference is the use of SUBSTITUTE in my final formula. I used SUBSTITUTE to replace letter E with a symbol because in the fifth string in the above list, the RIGHT function in my formula will return the following: {"0";"E0";"3E0";"C3E0";"2C3E0";"B2C3E0";"1B2C3E0";"A1B2C3E0"} where the third string 3E0 will return TRUE by ISNUMBER function, and this will result in an incorrect answer. Therefore I need to get rid of letter E first.
Let me know if you have any questions. Cheers :)

Excel Countif with wildcards in searched array

I've searched for a while, but it looks like all the examples I find are the opposite of what I need. There are many ways to see if a string with wildcards matches any of the values in an array, but I need to go the other way - I need the array to contain wildcards, and check if the string in the target cell matches any of the match strings in the array, but the match strings can contain wild cards.
To put it in context, I am parsing large log files, and there are many lines I wish to ignore (but not delete); so I have a helper column:
+---+-------+----------------------------------------+----------------------------+
| | A | B | C (filter for = FALSE) | Requirement
+---+-------+----------------------------------------+----------------------------+
| 1 | 11:00 | VPN Status | =COUNTIF(IgnoreList,B1)>0 + Keep
| 2 | 11:05 | Log at event index 118, time index 115 | =COUNTIF(IgnoreList,B2)>0 + Ignore
| 3 | 11:20 | Log at event index 147, time index 208 | =COUNTIF(IgnoreList,B3)>0 + Ignore
+---+-------+----------------------------------------+----------------------------+
I've tried to put wildcards in my IgnoreList range to catch any of the "Log at event" lines:
+--------------------------------------+
| IgnoreList +
+--------------------------------------+
| State Runtime 1 +
| State Runtime 2 +
| State Runtime 3 +
| State Runtime 4 +
| Log at event index *, time index * +
+--------------------------------------+
... but this isn't working.
Does anyone know how to check a cell against an array containing wildcards?
My IgnoreList has 60 entries so far, so testing each cell individually isn't really feasible. I could have 30,000 or more entries in the log, so individual testing will be a lot more formulas than I'd hoped to use. I also don't want to edit the formulae when I add an entry to the IgnoreList.
Thanks for your help!
Use SEARCH, which allows wild card lookups, inside SUMPRODUCT:
=SUMPRODUCT(--ISNUMBER(SEARCH(IgnoreList,B1)))>0
To use COUNTIF one would need to reverse the criteria and wrap in SUMPRODUCT:
=SUMPRODUCT(COUNTIF(B1,IgnoreList))>0

Exact frequency of a specific word in a single cell (excluding suffix and prefix)

I earlier worked out a good solution for this with the help of the comunity, it works really good but I found out it can only handle suffix words (it dosen't ignore prefix-words).
Formula:
=IF(B1<>"";(LEN(A1)-LEN(SUBSTITUTE(A1;B1&" ";"")))/(LEN(B1)+1)+IF(RIGHT(A1;LEN(B1))=B1;1;0);"")
A contains sentences, multiple words (without punctuation)
B contains the word I want to count the exact frequency of.
C here is there the formula is placed and where I get the result
Sample table:
| A | B | C |
|:-------------------------:|:----:|:--------:|
| boots | shoe | 0 |
----------------------------------------------|
| shoe | shoe | 1 |
----------------------------------------------|
| shoes | shoe | 0 |
----------------------------------------------|
| ladyshoe dogshoe catshoe | shoe | 3 |
----------------------------------------------|
In C-column I am getting correct output in row 1, 2 and 3 but not 4. I want C4 should return 0 and not 3.
The problem is that it makes no match for shoexxxxxxxxxxx (correct) but makes a match for xxxxxxxxxxxshoe (wrong).
I only want the formula to count the exact match for shoe, any other word should not be counted for.
You want this formula:
=IF(B1<>"",(LEN(A1)-LEN(SUBSTITUTE(A1," "&B1&" ","")))/(LEN(B1)+2),"")+IF(A1=B1,1,0)+IF(LEFT(A1,LEN(B1)+1)=B1&" ",1,0)+IF(RIGHT(A1,LEN(B1)+1)=" "&B1,1,0)
I'll denote a space by * to make the following clearer:
There are four cases to consider:
string; the word has no spaces on either side (and is therefore the only word in cell A1
string*; the word appears at the start of a list of words.
*string; the word appears at the end of a list of words.
*string*; the word is in the middle of a list of words.
First we count the number of occurrences of *string*, by substituting "*string*" for "", subtracting the length of the new string from the old one, and dividing by len(string)+2 (which is the length of *string*).
Then we add one more to our count if A1 is exactly string, with no spaces either side.
Then we add one more if A1 starts with string*, and one more if A1 ends with *string.

Specific concatenation of text cells by formula

I'm having difficulty producing a CONCATENATE formula that combines text cells in the way that I want. There are five fields that I want to concatenate: Title, Forename, RegnalNumber, Surname, and Alias, in that order. I'm no regex expert, so excuse the poor formatting, but this is a rough way of expressing what I'm trying to achieve:
(title)? (forename) (regnalnumber)? (surname)?, (alias).
The only field that can't be null is the forename field, although it might have the value "?", in which case it shouldn't output anything in the concatenation, i.e. it should be treated as blank. Hopefully the following test cases should demonstrate the output I'm trying to achieve: the output on the right is what it should look like:
| Title | Forename | RN | Surname | Alias | CONCATENATE |
+--------+----------+----+-----------+--------------+---------------------------------------+
| Ser | Jaime | | Lannister | Kingslayer | Ser Jaime Lannister, Kingslayer |
| | Pate | | | | Pate |
| Lord | ? | | Vance | | Lord Vance |
| King | Aerys | II | Targaryen | The Mad King | King Aerys II Targaryen, The Mad King |
| Lord | Jon | | Arryn | | Lord Jon Arryn |
| | Garth | | | Of Oldtown | Garth, Of Oldtown |
I've experimented for ages trying to make this concatenation work, but haven't been able to get it right. This is the current formula, with cell references replaced by the field name for comprehensibility:
=CONCATENATE(IF(Title<>"",Title&" ",""),IF(AND(Forename<>"",Forename<>"?"),Forename,""),IF(RN<>""," "&RN,""), IF(OR(AND(Forename<>"", Forename<>"?"), Surname<>"", RN<>""), " ",""), IF(Surname<>"",Surname,""),IF(AND(Alias<>"",OR(Alias<>"",AND(Forename<>"", Forename<>"?"),Surname<>"")),", "&Alias, Alias))
There is one case where it doesn't work: if the Surname and RN are null but the the Forename and Alias are non-null. For example, if the Forename is Garth, and the Alias is Of Oldtown, the concatenation outputs: Garth , Of Oldtown. It's the same if the title is non-null. It shouldn't have a space before the comma.
Can you help me to fix this formula so it works as expected? If you can find a way to simplify it, even better! I know I'm probably overcomplicating this a great deal. I'm using LibreOffice Calc 4.3.1.2, not Excel.
The best way imho to solve situations like this is to divide the problem over multiple simple columns, rather than 1 huge complex formula. Remember you can always hide the columns that you don't want to see.
So create a column for Title that says =if(a2="","",a2&" ").
That can be extended for all the other columns, except:
for Forename, where you want to include the "?" as follows: =if(b2="?","",b2&" ")
for Alias, where you want to include the leading ",": =if(e2="","",", "&e2)
Lastly just concatenate each of your working columns with something like: =f2&g2&h2&i2&j2.
This breaks the problem down into very simple components, and makes it easy to debug. If you want to add extra functionality at a later stage, it is easy to swap out one of your formulae for something else.
I know this is only a bit of fun, but can I suggest a more algorithmic approach?
The algorithm is:-
If a field is empty or ?, do nothing
Else
If concatenation so far is empty, add field to concatenation
Else
Add a space followed by the field to concatenation
which leads to this formula in G2 :-
=IF(OR(A2="",A2="?"),F2,IF(F2="",A2,F2&" "&A2)
(need to put single apostrophes in column F to make it work)
which when copied across looks like this:-

Looking multiple values on multiple columns in excel

I have a table where each person has several "Job" columns. I need to find all the employees who has a specific value ("Actor") in one of their "Job" columns.
I thought about doing HLookup on multiple columns, but Lookup functions only returns the first match (and I'm not sure I can use it on multiple columns). I also tried Pivot Tables, but all I got is aggregation, not the exact matches. How can I solve it?
For example, from the sample data below, when looking for "Actor", I would like to get both "John, Doe" and "Todd, Dude"
Sample data:
Id | First Name | Last Name | email | Job1 | Job2 | Job3 | Job4
-----------------------------------------------------------------------------------
1 | John | Doe | jd#i.com | Actor | Photographer | Producer |
2 | Todd | Dude | sd#i.com | Lights | Actor | |
3 | Janis | Joplin | jj#i.com | Singer | | |
Assuming the table as you give it is in A1:H4 (with headers in row 1), and that you put e.g. "Actor" in J1, this array formula** in J2:
=IFERROR(INDEX($B$2:$B$4&" "&$C$2:$C$4,SMALL(IF($E$2:$H$4=J$1,ROW($E$2:$H$4)-MIN(ROW($E$2:$H$4))+1),ROWS($1:1))),"")
Copy down until you start to get blanks. The formula may also be copied across to give results for other professions listed in K1, L1, etc.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
I have no idea, how to it in one formula. All lookups and match returns only first reference. You could add column jobActor --- true if one of the jobs is Actor and then create pivot --- filter on jobAll, row names is person names.
Maybe advanced filter could be the way how to do it.

Resources