Home

Vlookup to find multiple variations of a text string and return column

%3CLINGO-SUB%20id%3D%22lingo-sub-655733%22%20slang%3D%22en-US%22%3EVlookup%20to%20find%20multiple%20variations%20of%20a%20text%20string%20and%20return%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-655733%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20what%20I%20have%20so%20far%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DVLOOKUP(%22*%22%26amp%3B%24H%242%26amp%3B%22*%22%2C%20Datatable%2C%20COLUMN(A2)%2C%20FALSE)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24H%242%20%3D%20Contains%20the%20text%20I'm%20searching%20for%20within%20Datatable%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20I%20run%20the%20formula%2C%20I%20only%20get%20the%20first%20instance%20of%20the%20text.%20However%2C%20I%20know%20there%20is%20more%20than%20one%20case%20that%20contains%20this%20text%20within%20the%20Datatable.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20help.%20I%20feel%20like%20I'm%20so%20close%20to%20getting%20this%20to%20work.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-655733%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Evlookup%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-655886%22%20slang%3D%22en-US%22%3ERe%3A%20Vlookup%20to%20find%20multiple%20variations%20of%20a%20text%20string%20and%20return%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-655886%22%20slang%3D%22en-US%22%3EHave%20you%20tried%20advanced%20filter%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-655929%22%20slang%3D%22en-US%22%3ERe%3A%20Vlookup%20to%20find%20multiple%20variations%20of%20a%20text%20string%20and%20return%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-655929%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3BYes%2C%20I%20have.%20It%20returns%20either%20all%20the%20data%20or%20a%20few%20items%20that%20don't%20contain%20the%20information%20I'm%20looking%20for.%20Could%20that%20be%20because%20the%20information%20is%20within%20a%20string%20of%20text%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-655936%22%20slang%3D%22en-US%22%3ERe%3A%20Vlookup%20to%20find%20multiple%20variations%20of%20a%20text%20string%20and%20return%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-655936%22%20slang%3D%22en-US%22%3EVLOOKUP%20with%20last%20argument%20of%20FALSE%20always%20returns%20the%20first%20instance.%20To%20return%20the%20last%20instance%2C%20LOOKUP%20is%20the%20best.%20To%20return%20any%20instance%20between%20the%20first%20and%20the%20last%2C%20INDEX-AGGREGATE%20would%20return%20your%20desired%20result%2C%20including%20the%20first%20and%20the%20last.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-656614%22%20slang%3D%22en-US%22%3ERe%3A%20Vlookup%20to%20find%20multiple%20variations%20of%20a%20text%20string%20and%20return%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-656614%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F351327%22%20target%3D%22_blank%22%3E%40Megpie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20a%20number%20of%20ways%20of%20achieving%20this%20with%20formulas.%3C%2FP%3E%3CP%3EOne%20is%20to%20use%20SEARCH%20to%20determine%20whether%20the%20search%20string%20is%20contained%20within%20the%26nbsp%3B%3CSPAN%3Etarget%20%3C%2FSPAN%3Elist.%26nbsp%3B%20Within%20a%20table%20this%20might%20be%20performed%20record%20by%20record%20using%20a%20helper%20field%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20ISNUMBER(%20SEARCH(searchString%2C%20%5B%40targetString%5D)%20)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Eor%20it%20would%20appear%20slightly%20differently%20within%20an%20array%20calculation%2C%20where%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20ISNUMBER(%20SEARCH(searchString%2C%20targetString)%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Egives%20the%20entire%20column%20of%20results%20either%20using%20CSE%20or%20Dynamic%20Arrays%20(Office%20365%20insider%20only%20at%20present).%26nbsp%3B%20I%20often%20place%20array%20calculations%20within%20a%20named%20formula%20where%20they%20may%20be%20referenced%20and%20calculated%20on%20demand%20(here%20I%20might%20use%20the%20name%20'%3CSTRONG%3Ematches%3F%3C%2FSTRONG%3E').%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20dynamic%20array%20calculation%20would%20then%20proceed%20with%3C%2FP%3E%3CP%3E%26nbsp%3B%3CSTRONG%3E%3D%20FILTER(%20Table1%2C%20matches%3F%20)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ewhich%20returns%20every%20matching%20record.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWith%20standard%20versions%20of%20Excel%2C%20things%20are%20a%20little%20more%20turgid.%26nbsp%3B%20I%20tend%20to%20define%20a%20further%20named%20array%20'%3CSTRONG%3Ek%3C%2FSTRONG%3E'%20to%20hold%20record%20numbers.%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20ROW(Table1%5BtargetString%5D)%20-%20ROW(Table1%5B%23Headers%5D)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%5Bthe%20formula%20is%20so%20pig-ugly%20it%20needs%20to%20be%20hidden%20but%2C%20in%20future%2C%20SEQUENCE%20will%20do%20a%20much%20better%20job%5D.%20%26nbsp%3BThe%20formula%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20IF(%20matches%3F%2C%20k%20)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Egives%20the%20row%20numbers%20for%20matched%20records%20padded%20with%20FALSE%20for%20failed%20matches%2C%20and%20then%20SMALL%20reduces%20the%20list%20to%20consecutive%20values%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3D%20SMALL(%20IF(%20matches%3F%2C%20k%20)%2C%20k%20)%2C%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ewhich%20can%20be%20used%20by%20INDEX%20to%20return%20the%20required%20records.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EA%20completely%20different%20strategy%20is%20to%20use%20MATCH%20to%20find%20the%20first%20record%20number%20and%20then%20to%20use%20INDEX%20to%20return%20the%20first%20cell%20of%20the%20remaining%20search%20field.%26nbsp%3B%20The%20second%20MATCH%20operates%20on%20the%20residual%20part%20of%20the%20table%2C%20and%20so%20on.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Megpie
New Contributor

This is what I have so far:

 

=VLOOKUP("*"&$H$2&"*", Datatable, COLUMN(A2), FALSE)

 

$H$2 = Contains the text I'm searching for within Datatable

 

When I run the formula, I only get the first instance of the text. However, I know there is more than one case that contains this text within the Datatable.

 

Please help. I feel like I'm so close to getting this to work.

4 Replies
Have you tried advanced filter?
Highlighted

@Jan Karel Pieterse Yes, I have. It returns either all the data or a few items that don't contain the information I'm looking for. Could that be because the information is within a string of text?

VLOOKUP with last argument of FALSE always returns the first instance. To return the last instance, LOOKUP is the best. To return any instance between the first and the last, INDEX-AGGREGATE would return your desired result, including the first and the last.

@Megpie 

There are a number of ways of achieving this with formulas.

One is to use SEARCH to determine whether the search string is contained within the target list.  Within a table this might be performed record by record using a helper field

= ISNUMBER( SEARCH(searchString, [@targetString]) )

or it would appear slightly differently within an array calculation, where

= ISNUMBER( SEARCH(searchString, targetString) 

gives the entire column of results either using CSE or Dynamic Arrays (Office 365 insider only at present).  I often place array calculations within a named formula where they may be referenced and calculated on demand (here I might use the name 'matches?').

 

The dynamic array calculation would then proceed with

 = FILTER( Table1, matches? )

which returns every matching record.

 

With standard versions of Excel, things are a little more turgid.  I tend to define a further named array 'k' to hold record numbers.

= ROW(Table1[targetString]) - ROW(Table1[#Headers])

[the formula is so pig-ugly it needs to be hidden but, in future, SEQUENCE will do a much better job].  The formula

= IF( matches?, k )

gives the row numbers for matched records padded with FALSE for failed matches, and then SMALL reduces the list to consecutive values

= SMALL( IF( matches?, k ), k ),

which can be used by INDEX to return the required records.

 

A completely different strategy is to use MATCH to find the first record number and then to use INDEX to return the first cell of the remaining search field.  The second MATCH operates on the residual part of the table, and so on.

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
21 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
flashing a white screen while open new tab
cntvertex in Discussions on
12 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies