Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

Excel v-lookup referencing part of a text in a cell.

I am trying to use v-lookup to search part of the text in a cell and have the information displayed.

The formula is entered in cell is J2 in sheet2 and contains urls like the ones listed  below

www.acs.acct/mus.com <  i.e I would like to match ACCT to column N in spreadsheet 2 >
www.org.estm/cst.com 
www.can.logon/can.com


The array looks like this which is on spreadsheet sheet 2

      column N  column O
     -----------    ------------
1.   acct            Account
2.   estm          Estatement
3.   logon         Logon

Here is the formula I attempted to use

=  Vlookup ( "*" & H1 & "*",  sheet3!N1:011,2,False

Nothing happen, is there a way to do a vlookup by referencing part of a text in a cell.
0
DAN2011
Asked:
DAN2011
  • 6
  • 4
  • 3
  • +1
1 Solution
 
SteveCommented:
Try the follwoing to get just the "acct"...

=MID(H1,FIND(".",H1,5)+1,FIND("/",H1)-FIND(".",H1,5)-1)

in the lookup it would be:

=VLOOKUP(MID(H1,FIND(".",H1,5)+1,FIND("/",H1)-FIND(".",H1,5)-1), sheet3!$N$1:$0$11,2,False)
Example.xlsx
0
 
terencinoCommented:
Or you could use a simple array formula like so...
Lookup array formulaEnter the formula into the first cell, then hit Ctrl+Shift+Enter all at the same time to enter it as an array formula with the {curly brackets} then drag down the rest of the cells
...Terry
ArrayFormulaLookup.xlsx
0
 
SteveCommented:
Nice suggestion Terry, I like it... although...

Need to add '$' to the formula to make sure that the lookup range does not increment as you drag...
=IF(FIND(B$1:B$3,B6)>0,C$1:C$3,"")

And upon doing this the formula sems to fail... am I doing something wrong?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
terencinoCommented:
Good pickup The_Barman thank you!
Usually I would name the ranges
0
 
barry houdiniCommented:
As The_Barman says, though, if you fix the references or name the ranges then the results in C6/C7 are errors - the formula only works in cases where the first row is a match.

Perhaps try this "non-array" version

=LOOKUP(2^15,FIND("."&B$1:B$3&"/",B5),C$1:C$3)

regards, barry
0
 
SteveCommented:
you could use :

=INDEX($C$1:$C$3,MAX(IF(ISERROR(FIND($B$1:$B$3,B6)),-1,1)*(ROW($B$1:$B$3)-ROW($B$1)+1)))


But (as ever) Barry smacks this one out of the park... nice formula Barry :)

And as ever, I must ask... Barry... How does that work (in particular the "2^15")??
ArrayFormulaLookup.xlsx
0
 
barry houdiniCommented:
Thanks Steve, my suggestion uses the same principle as this formula

=LOOKUP(9.99E+307,A1:A10,Z1:Z10)

That finds the last number in A1:A10 and returns the corresponding value in Z1:Z10. That works because 9.99E+307 is (almost) the largest number you can enter in a cell in Excel so, assuming no number that large is found in A1:A10 it always matches with the last number (ignoring any text or errors).

In this version.....

=LOOKUP(2^15,FIND("."&B$1:B$3&"/",B5),C$1:C$3)

....notice that FIND is looking for the lookup values surrounded by comma and forward slash, thereby avoiding any false matches. FIND will produce an error or a number - the number being limited by the maximum number of characters in a cell - which is 2^15-1

.....So you can use 2^15 as lookup value and you know that it will be greater than any number returned by FIND.

Of course if there is more than one match you'll get the last one (unlike VLOOKUP which will give you the first match)

regards, barry
0
 
SteveCommented:
Well, that is my one thing learned for the day.

Thanks for the explanation Barry.
Another tool to add to my repertoire.

ATB
Steve.
0
 
DAN2011Author Commented:
when i tried the formula
=LOOKUP(2^15,FIND("."&B$1:B$3&"/",B5),C$1:C$3) /I got N/A

=INDEX($C$1:$C$3,MAX(IF(ISERROR(FIND($B$1:$B$3,B6)),-1,1)*(ROW($B$1:$B$3)-ROW($B$1)+1)))/I got n/A #VALUE!/

=IF(FIND(B$1:B$3,B6)>0,C$1:C$3,"") / did not  produce a result.

For example if the URL was
The url                                   The lookup value would be      To Be displayed in J1

www.online.act.exp.com        act                                              Account

Thanks
0
 
terencinoCommented:
For the middle formula did you enter it as an array formula (pressing Ctrl+Shift+Enter instead of Enter)?
0
 
DAN2011Author Commented:
I tried hardcoding the lookup with the code ----> lookup("*act*",$AI$1:$AJ$12,2,False)  which worked partially.  I got the result Account, however this only account for the urls that contains act. Is it away to hardcode multiple values?
0
 
terencinoCommented:
Did you change the ranges in the formulas to match your ranges? Can you send a sample of the spreadsheet you are using, that will help with setting up the formulas correctly for you
0
 
SteveCommented:
OK, BarryHoudinis formula works based upon the question asked... but the adress has changed as it no longer has '\' in it... try...

=LOOKUP(2^15,FIND(B$1:B$3,B5),C$1:C$3)
ArrayFormulaLookup.xlsx
0
 
DAN2011Author Commented:
Attached  is a sample of the spreadsheet. FYI, the actual maximum rows is 2000 and the url varies. The first row is a example.

In the example, est in found in the URL(column b) in row one on sheet1.  I would like est to be looked up from the table displayed in the second sheet(lookup) and have eStatement displayed in column c of the first sheet. The lookup table does not have to be in the second sheet like it is in the attached example it can be  on the first worksheet if you see fit, as long as it appears  in a  distant column like AI.
Workbookexp.xlsx
0
 
SteveCommented:
Attached is your original file with the working formula...
Note the case sensitivity in first original file.

I have also attached a two formula workbook...
This includes dynamic ranges (bold) and no case sensitivity in both.
Workbookexp.xlsx
Workbookexp.xlsx
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now