Find whether part of a cell matches with another entire and exact cell

chabuka

New Member
Joined
Jan 28, 2019
Messages
3
Hi,

firstly thank a lot for reading and hopefully answering my question.
I need to find cells that within their string contain the content of a different cell. I think I'm having trouble because I need to refer back to the cell with the string and I'm failing miserably at it. Here the situation:

Column A has a suggestion of possible "genes" and looks like this:
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMAN
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMAN

Column B is a list of genes like:
NB5R3
LMNB1
PRDCX
LM

You will find that cells in column A have many suggestions for the right type of gene (the genes are always hidden inbetween "|" and "_" if that helps with the formula) and column B has the genes that I'm interested in. If any one of the genes in B:B is part of a cell in e.g A1, I need to know that. Any form of highlighting (TRUE/FALSE, Yes/No, COUNT or other) would help.
I can easily highlight cells in B that contain anything from A (=COUNTIF(A:A,"*"&B1&"*")), but with limitations and I didn't manage to do it the other way around which is actually more helpful.

I have tried quite some formulas, e.g.
=IF(SUMPRODUCT(--ISNUMBER(SEARCH(B:B,A1))),"Yes","No")
=IF(SUMPRODUCT(--MATCH(SEARCH(B:B,A1))),"Yes","No")

but they all were error-prone. I think it has got to do with problems arising from short gene names (e.g. LM) that collide with other gene names (e.g. LMNB1).
I need to find a way to refer to finding the exact content of any of the B cells anywhere within a certain cell in e.g. A1 without finding wrong positives.
I hope this explanation was ok. Thanks in advance, I really apreciate your help!
Lina
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe a VBA to highlight cells in Col A
Code assumes cols A & B and both start at row 1


Code:
Sub MM1()
Dim lr As Long, r As Long, x As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = 1 To lr
    For x = 1 To 4 'change col B range to suit
        If InStr(Range("A" & r).Value, Range("B" & x).Value) <> 0 Then
            Range("A" & r).Interior.ColorIndex = 3
        End If
    Next x
Next r
End Sub
 
Upvote 0
(This does not answer your question but may be helpful)

Your original formula would not distinguish between NB5R3 and NB5R33 and ZNB5R3 and therefore could result in false positives
=COUNTIF(A:A,"*"&B1&"*")

Try this instead
=COUNTIF(A:A,"*|"&B2&"_*")
 
Upvote 0
maybe something like this
Column1Column1.1Yes / No
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMANNB5R3Yes
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMANLMNB1No
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMANPRDCXNo
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMANLMNo
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMANNB5R3No
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMANLMNB1Yes
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMANPRDCXNo
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMANLMYes

if you are able to use PowerQuery
 
Last edited:
Upvote 0
Here is one way

In C2 and copy down to get EXACT string only
="|"&B2&"_"

In D2 and copy down
=IF(SUMPRODUCT(--ISNUMBER(SEARCH($C$2:$C$6,A2))),"Yes","No")

BUT C2:C6 cannot contain any blank cells
- becomes a problem to vary the number of items
- one way would be to use a bigger range than required and put dummy values in the extra cells
eg to allow for 19 items $C$2:$C$20 and fill $C$7:$C$20 with ZZZZZ (ie something that would not be found)

A more elegant way would be to use a dynamic range named MyRange, with RefersTo formula
=OFFSET(Sheet1!$C$2,0,0,COUNTA(Sheet1!$C$2:$C$20))

and in E2 copied down
=IF(SUMPRODUCT(--ISNUMBER(SEARCH(myRange,A3))),"Yes","No")

Excel 2016 (Windows) 32 bit
A
B
C
D
E
1
PossibleLooking forExact string
2
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMANNB5R3|NB5R3_YesYes
3
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMANLM|LM_YesYes
4
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LM_HUMANPRDCX|PRDCX_YesYes
5
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LX_HUMANLMNB1|LMNB1_NoNo
6
P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB11_HUMANNB5R33|NB5R33_NoNo
7
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMAN|LM_HUMANYesYes
8
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R44_HUMAN:P00387|NB5R44_HUMAN:P00387-3|NB5R44_HUMAN|LM_HUMANYesYes
9
B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R44_HUMAN:P00387|NB5R44_HUMAN:P00387-3|NB5R44_HUMAN|LM44_HUMANNoNo
Sheet: Sheet1
 
Last edited:
Upvote 0
Hi all,

many, many thanks for your help!
Yongle, this is exactly what I need. I have tried it and it works a treat. In the past I was trying to split the cells in A into many cells (text to columns) but that was very messy as sometimes there is one gene suggestion and sometimes up to 25. The way how you suggest it with additional columns C and D will be entirely sufficient as my list in B is always the same without any blank cell danger. But I'm sure someone reading this post will need that in the future.
Sandy, Michael, thank you for your suggestions also! But not being familiar with PowerQuery and very rudimental on VBA, I will go the path of least resistance with Yongle's proposed formulas.

I really appreciate you all taking the time to help others. You have made my excel life much easier.

Best regards,
Lina
 
Upvote 0
Hi,

Here's another way, no helper column needed:


Book1
ABC
1PossibleLooking for
2B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMANNB5R3Yes
3P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB1_HUMANLMYes
4P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LM_HUMANPRDCXYes
5P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LX_HUMANLMNB1No
6P02545-2|LMNA_HUMAN:P02545-6|LMNA_HUMAN:P02545|LMNA_HUMAN:E9PBF6|E9PBF6_HUMAN:P20700|LMNB11_HUMANNB5R33No
7B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R3_HUMAN:P00387|NB5R3_HUMAN:P00387-3|NB5R3_HUMAN|LM_HUMANYes
8B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R44_HUMAN:P00387|NB5R44_HUMAN:P00387-3|NB5R44_HUMAN|LM_HUMANYes
9B1AHF3|B1AHF3_HUMAN:P00387-2|NB5R44_HUMAN:P00387|NB5R44_HUMAN:P00387-3|NB5R44_HUMAN|LM44_HUMANNo
Sheet510
Cell Formulas
RangeFormula
C2=IF(ISNUMBER(LOOKUP(2,1/SEARCH("|"&B$2:B$6&"_",A2))),"Yes","No")


Formula copied down.
 
Upvote 0
You're welcome, welcome to the forum.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top