Check if array contains text from a list and when a value apears more then once display that value - excel-formula

What if I have 4 columns with data, and want the value that is more than once in those 4 columns(A-B-C-D).
apple pear melon grape
melon apple melon grape
pear melon melon pear
My list in column E is;
``
apple
pear
melon
grape
And what I would like is that in column F the value appears of the fruit that is more than once in a row.
So F1 should return nothing, F2 should return "melon", and F3 should return "pear, melon"
Is that posible with a formula?

Try,
In B1, array ("Ctrl"+Shift"+"Enter") formula copied down :
=MID(TEXTJOIN(", ",,FILTERXML("<a>A<b>"&SUBSTITUTE(TRIM(A1)," ","</b><b>")&"</b></a>","a|a/b[not(preceding::* =.)][following::* =.]")),4,999)
Remark : If you have Office 365, the above formula is normal entry.
If source data put in separated cells, then formula become >>
In F1, array ("Ctrl"+Shift"+"Enter") formula copied down :
=MID(TEXTJOIN(", ",,FILTERXML("<a>A<b>"&TEXTJOIN("</b><b>",,A1:D1)&"</b></a>","a|a/b[not(preceding::* =.)][following::* =.]")),4,999)
Remark : If you have Office 365, the above formula is also normal entry.

Related

How to delete duplicate rows and keep the nth occurrence on Excel?

In Excel I want to delete duplicate rows but I want to have some preferences for what duplicate occurrence to keep. As in Excel while removing duplicates it by default keeps the first occurrence. Is there any way to keep the 2nd or 3rd occurrence?
For example:
a Apple
a Banana
a Cherry
b Apple
b Banana
b Melon
c Apple
c Cherry
c Melon
By default if I remove duplicate, it would be like this:
a Apple
b Apple
c Apple
But is there a way to achieve this
a Banana
b Banana
c ?
As the C doesn't have banana, we can keep this blank, or any default value.
To always keep the second occurrence,
SORT the data,
MATCH the elements among itself to get the first occurrence,
Subtract the matched row number from actual row number and if it's not 1, filter it out.
Input:
Duplicates
Helper column
a
Apple
a
Cherry
b
Apple
c
Apple
c
Cherry
b
Banana
b
Melon
a
Banana
c
Melon
Formula:
=FILTER(SORT(A1:B9,1,1),ROW(A1:A9)-MATCH(SORT(A1:A9),SORT(A1:A9),0)=1)
Output:
Second occurrence
Helper column
a
Cherry
b
Banana
c
Cherry
see:
=FILTER(A1:B, COUNTIFS(A1:A, A1:A, ROW(A1:A), "<="&ROW(A1:A))=2)
for 3rd occurrence change 2 to 3

Same value against each cell from a single column?

I have one column like below:
Fruits:
Apple
Banana
Mango
Vegetables:
Broccoli
Tomato
Potatoes
I would like each value to have their parent name next to it in the cell like below:
Apple Fruit
Banana Fruit
Mango Fruit
Broccoli Vegetables
Tomato Vegetables
Potatoes Vegetables
How can I achieve this?
If your data is in column A, I am able to get the result with a helper column, by using the following formula in B1:
=FILTER($A:$A,($A:$A<>"")*(RIGHT($A:$A,1)<>":"))
This will result in your data excluding the titles (fruit, vegetable).
Then in C1 use the following formula and drag down:
=IFERROR(B1&" "&SUBSTITUTE(LOOKUP(2,1/(RIGHT(INDIRECT("$A$1:$A"&MATCH(B1,$A:$A,0)),1)=":"),INDIRECT("$A$1:$A"&MATCH(B1,$A:$A,0))),":",""),"")
As per my below screenshot put below formula to B1 cell.
=IF(RIGHT(A2,1)=":",LEFT(A2,LEN(A2)-1),B1)
Then put following formula to C1 cell
=FILTER(A2:B9,RIGHT(A2:A9,1)<>":")

How do I highlight a cell in Excel when all its content is contained in another column

I have a column (column A) that contains a list of text and another column (column B) that contains a smaller list, which is the values that I actually care about. Is it possible to only highlight cells in column A if all of its contents is listed in column B? If so, how?
A B
Apple Apple
Peach Pear
Apple, Pear Plum
Apple, Grape Kiwi
Apple, Pear, Kiwi      
Watermelon, Grape
So in the above example, I would like to highlight A1, A3, and A5 because all of the contents is listed somewhere in column B
use the following formula for the Conditional formatting:
=AND(ISNUMBER(MATCH(FILTERXML("<a><b>"&SUBSTITUTE($A1,",","</b><b>")&"</b></a>","//b"),$B:$B,0)))
If one does not have FILTERXML then they can use:
=SUMPRODUCT(--ISNUMBER(SEARCH("," &$B$1:$B$4&",",","&SUBSTITUTE(A1," ","")&",")))=LEN(A1)-LEN(SUBSTITUTE(A1,",",""))+1
Noting that the range $B$1:$B$4 must be the size of the lookup values without any blanks

how can Ifind specific text in excel and return with specific value?

How can I find text in a cell and output should be a return value?
For example:
Find Apple in Cell A1, if true it will output "return value for apple"
If the search is false, it will always search the next row. If true it will stop.
Fruits: Apple, Banana, Cherry
Fruits
A1: 1 Apple
A2: 2 Banana
A3: 5 Cherry
Return Value
B1: Apple
B2: Banana
B3: Cherry
Search Fruits
D1: Banana
D2: Cherry
D3: Apple
User search formula: You need to put your query more clearly.
=IFERROR(IF(SEARCH("Apple",A1)>0,"Apple",""),"")

Count of unique values in multiple columns

What I need is probably best described in an example. It's a bit different from the group functionality and also the PivotTable in Excel, because I want it to show up in the data row itself (and not off to the side or below, etc.). Given a table like:
Fruit Color Farmer
Banana Yellow Smith
Banana Yellow Smith
Apple Yellow James
Apple Yellow James
Apple Green Smith
Banana Yellow James
I want to take the first two columns and give the count of rows that have the same values (regardless of the values in the other columns). So for my example, I would get:
Fruit Color Count Farmer
Banana Yellow 3 Smith
Banana Yellow 3 Smith
Apple Yellow 2 James
Apple Yellow 2 James
Apple Green 1 Smith
Banana Yellow 3 James
My preference would be an Excel formula (or even a built in function) as opposed to VBA.
Assuming Fruit is in A1, please try in C2 (having made room for it):
=COUNTIFS(A:A,A2,B:B,B2)
and copy down to suit.

Resources