Check if cell contains partial text string based on string in another cell

silviosilver

New Member
Joined
Aug 12, 2015
Messages
24
I want to check whether a cell contains a partial match with a text string in another cell.

Say A1 contains the string ABCDEFG, I want to check if B1 contains any part of ABCDEFG - eg ABC or CDE or DEFG.

But I don't want to have to manually enter "ABC" or "CDE" or "DEFG" in searching for a match, I want this to occur automatically based on the string that is (in this example) in A1.

How can I do this?
 

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.
try
Power Query:
Contains = Table.AddColumn(Source, "Contains", each if Text.Contains([RawData], [IsIn]) then [IsIn]  else null)
as the third column
btw. this is case sensitive so ABC <> abc
 
Upvote 0
with this should be easier
RawDataIsInContains
ABCDEFGCDEFCDEF
ABCDEFGHJK
ABCDEFGGHI
ABCDEFGBB
ABCDEFGDEDE
ABCDEFGAG
ABCDEFGcdefg

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Contains = Table.AddColumn(Source, "Contains", each if Text.Contains([RawData], [IsIn]) then [IsIn]  else null),
    TSC = Table.SelectColumns(Contains,{"Contains"})
in
    TSC
 
Upvote 0
Thanks, Sandy.

Sorry to be a complete idiot, but what do I do with that? I really have no idea.

I'm unfortunately away from home now, but just playing around on the Excel I have available at the moment, I seem to have achieved my original goal with the simple SEARCH function. I'm not sure why this wasn't working when I tried it at home. (Being half asleep probably didn't help.) I'll have to check a bit later.
 
Upvote 0
It does seem like just some variant of =SEARCH(B1,A1) would do it - perhaps wrapped in ISNUMBER if you just want a True/False result.
 
Upvote 0
to use Power Query you need Excel with Power Query (I don't know which version you have right now, away from home)
with XL2016 : Data tab - New Query - From Other Sources - Blank Query then open Advanced Editor and replace all there with code copied from the post
remember that your source data should be an Excel Table (Ctrl+T) and the name of this table should be the same as in the code (here: Table1)
also adapt the headings to your version of the table
or
as RoryA mentioned you can use SEARCH() (case insensitive) or FIND() (case sensitive)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,034
Messages
6,122,782
Members
449,095
Latest member
m_smith_solihull

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