FInding a string within a string ?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi
this is probably basic stuff but I've never done this before

I have a code table:
REDRed
BLABlack
BLUBlue
YELYellow
PINPink
etc....

and I have long strings like
002147YELXR3
00732933BLA22
etc...

trying to output in next column to string the name of the code like above would be
Yellow
Black

if the color codes we're in fixed position I could do this easily but the codes can be in ANY part of the string.


Best way to do this ?

thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try this

Book1
CDEF
2
3REDRED
4BLABLACK
5BLUBLUE
6YELYELLOW
7PINPINK
8
9
10002147YELXR3YELLOW
11
Sheet4
Cell Formulas
RangeFormula
F10F10=LOOKUP(999999,IF({1,0},SEARCH(D3:D7,D10)^0*(ROW($D$3:$D$7)-ROW($D$3)+1),$E$3:$E$7))
 
Upvote 0
Using Power Query called Get and Transform in 2016 and later versions.
1. Bring each table into PQ Editor.
2. With Table1 listing the codes the following Mcode is applied to parse out the 3 letter color code.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Duplicated Column" = Table.DuplicateColumn(Source, "Column1", "Column1 - Copy"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Duplicated Column", "Column1", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Column1.1", "Column1.2"}),
    #"Split Column by Character Transition1" = Table.SplitColumn(#"Split Column by Character Transition", "Column1.2", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Column1.2.1", "Column1.2.2"}),
    #"Split Column by Position" = Table.SplitColumn(#"Split Column by Character Transition1", "Column1.2.1", Splitter.SplitTextByPositions({0, 3}, false), {"Column1.2.1.1", "Column1.2.1.2"})
in
    #"Split Column by Position"

3. The two tables are now joined (merged in PQ terminology) with a left inner join. The Mcode for that follows

Power Query:
let
    Source = Table.NestedJoin(Table1, {"Column1.2.1.1"}, Table2, {"Column1"}, "Table2", JoinKind.LeftOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Column2"}, {"Table2.Column2"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Column1.1", "Column1.2.1.1", "Column1.2.1.2", "Column1.2.2"})
in
    #"Removed Columns"

Solution shown below

Book8
AB
1Column1 - CopyTable2.Column2
200732933BLA22Black
3002147YELXR3Yellow
Sheet3
 
Upvote 0
@CA_Punit
i tried the formula but with my large dataset and it just outputs zero
Code:
=LOOKUP(999999,IF({1,0},SEARCH(B2:B200000,I2)^0*(ROW($B$2:$B$200000)-ROW($B$2)+1),$C$2:$C$200000))

Lookup value is I2
Code column is B
Name column is C
 
Upvote 0
@alansidman

unsure where to put the 2nd PQ
i tried it on table 2 and gives cyclic expression error

would prefer formula solution (or VBA) if its possible
 
Upvote 0
If Yes just replace the search

(SEARCH(B2:B200000,I2))

with this

SEARCH(IF(($B$2:$B$20000<>""),($B$2:$B$200000),REPT("Z",900)),I2)
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,179
Latest member
fcarfagna

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