VLOOKUP that returns a substring (defined by specific delimiters)that contains specific characters

dagda13

New Member
Joined
May 18, 2019
Messages
44
Hi,

I've been trying figure out (preferably without INDEX or arrays...my computer is too slow to handle them when dealing with hundreds of rows) a way to perform a VLOOKUP that will return a sub-string (said sub-string defined by the "|" delimiter) that contains specific characters. These sub-strings could be anywhere (no fixed position) in the string.

For example, if I perform a VLOOKUP and want to return a sub-string (with "|" delimiters) that contains "_ptbr", I would want to get "ds_box17_01_ptbr" because it is within the "|" delimiter and contains the specific "_ptbr" characters:

Lookup ValueString containing Sub-StringDesired Output
ds_box17_01_enus|ds_box17_01_dede|ds_box17_01_zhcn|ds_box17_01_frfr|ds_box17_01_ptbr|ds_box17_01_es|ds_box17_01_ptbr

Is there a way to do this? Any help very much appreciated!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

aRandomHelper

Active Member
Joined
Jan 14, 2021
Messages
301
Office Version
  1. 2016
Platform
  1. Windows
Probably not the best formula out there, but hope this helps:

Book1.xlsm
ABC
1Lookup ValueString containing Sub-StringDesired Output
2ds_box17_01_enus|ds_box17_01_dede|ds_box17_01_zhcn|ds_box17_01_frfr|ds_box17_01_ptbr|ds_box17_01_es|ds_box17_01_ptbr
3|ds_box17_01_dede|ds_box17_01_zhcn|ds_box17123_01_ptbr|ds_box17_01_es|ds_box17123_01_ptbr
41st_ds_box17_01_ptbr|ds_box17_01_es|1st_ds_box17_01_ptbr
5|ds_box17_01_dede|abcde|ds_box17_01_frfr|last_ds_box17_01_ptbrlast_ds_box17_01_ptbr
Sheet7
Cell Formulas
RangeFormula
C2:C5C2=IF(ISERR(FIND("_ptbr",MID(IFERROR(LEFT(B2,FIND("|",B2,FIND("_ptbr",B2))-1),B2),IFERROR(FIND("||",SUBSTITUTE(B2,"|","||",LEN(IFERROR(LEFT(B2,FIND("|",B2,FIND("_ptbr",B2))-1),B2))-LEN(SUBSTITUTE(IFERROR(LEFT(B2,FIND("|",B2,FIND("_ptbr",B2))-1),B2),"|",""))))+1,1),999))),"",MID(IFERROR(LEFT(B2,FIND("|",B2,FIND("_ptbr",B2))-1),B2),IFERROR(FIND("||",SUBSTITUTE(B2,"|","||",LEN(IFERROR(LEFT(B2,FIND("|",B2,FIND("_ptbr",B2))-1),B2))-LEN(SUBSTITUTE(IFERROR(LEFT(B2,FIND("|",B2,FIND("_ptbr",B2))-1),B2),"|",""))))+1,1),999))


Keep your Vlookup formula in column B, and place this formula in column C.
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
51,832
Office Version
  1. 365
Platform
  1. Windows
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

I'm also wondering if you have given us a big enough sample to fully understand what you have and what you are trying to achieve. Could you give us a slightly bigger sample, including the expected result(s), with XL2BB?

Make sure your sample(s) show us what sort of variety there might be in the original data and the expected results.
 

jtakw

Well-known Member
Joined
Jun 29, 2014
Messages
6,007
Office Version
  1. 2016
Platform
  1. Windows
Hi,

If in case the samples provided by @aRandomHelper is representative of your data, here's another formula to consider:

Book3.xlsx
ABC
1Lookup ValueString containing Sub-StringDesired Output
2ds_box17_01_enus|ds_box17_01_dede|ds_box17_01_zhcn|ds_box17_01_frfr|ds_box17_01_ptbr|ds_box17_01_es|ds_box17_01_ptbr
3|ds_box17_01_dede|ds_box17_01_zhcn|ds_box17123_01_ptbr|ds_box17_01_es|ds_box17123_01_ptbr
41st_ds_box17_01_ptbr|ds_box17_01_es|1st_ds_box17_01_ptbr
5|ds_box17_01_dede|abcde|ds_box17_01_frfr|last_ds_box17_01_ptbrlast_ds_box17_01_ptbr
Sheet909
Cell Formulas
RangeFormula
C2:C5C2=TRIM(RIGHT(SUBSTITUTE(LEFT(B2,FIND("_ptbr",B2)+4),"|",REPT(" ",99)),99))
 

Forum statistics

Threads
1,148,160
Messages
5,745,122
Members
423,927
Latest member
Pra56

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
Top