Nested IF Statement in VLOOKUP To Accomplish This?

censo

Board Regular
Joined
Dec 25, 2015
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
Hello,

I have a function that examines the first three characters of a string and then executes a VLOOKUP that returns the appropriate value. That works fine.

The challenge I'm having is including in that same formula an additional check that examines characters 5-7, or the value "FRT". The positioning will always be constant and fixed if hardcoded in, or if being searched for, only that sequence of "FRT" will ever be present so I know I would not receive false positives.

What would said function look like, do I need to nest an IF statement where it searches for "FRT", if not, run the above function I already have in place?

Thanks!



Excel 2013 32 bit
ABC
1SKUCURRENT OUTCOMEDESIRED OUTCOME
2WAL-12345644
3WAL-FRT-12345610
Sheet1
Cell Formulas
RangeFormula
B2=VLOOKUP(LEFT(A2,3),HANDLING,2,0)
Named Ranges
NameRefers ToCells
HANDLING=Sheet2!$A$2:$B$3




Excel 2013 32 bit
AB
1CODERESULT
2WAL4
3FRT10
Sheet2
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Like so?...

Excel 2010
ABC
1SKUCURRENT OUTCOMEDESIRED OUTCOME
2WAL-12345644
3WAL-FRT-12345610

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C2=IF(LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))=1,VLOOKUP(LEFT($A2,3),Sheet2!$A$2:$B$3,2,0),IF(LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))=2,VLOOKUP(MID($A2,5,3),Sheet2!$A$2:$B$3,2,0)))
C3Copy Down

<tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
wal-1234567894
abc-frt-98765432110
wal-frt-334455667710
abc-def-88776655no match
formula in B1 giving 4
=IF(ISERROR(SEARCH("frt",A1)),IF(ISERROR(SEARCH("wal",A1)),"no match",4),IF(ISERROR(SEARCH("frt",A1)),"no match",10))

<colgroup><col><col span="13"></colgroup><tbody>
</tbody>
 
Upvote 0
Like so?...

Thanks for the prompt reply, Jim. Your solution looks promising. Although I prefer to use a named range instead of cell references (apologies if I didn't make that clear before ... the array is way larger than what I've shown on Sheet2). With that said how would the function look like using "HANDLING" instead? I admit I'm not that skilled enough to dissect your solution to know where to make the replacement.
 
Upvote 0
formula in B1 giving 4


Thanks oldbrewer. Your proposed solution appears to be headed in the right direction; however, there would be many different 3 character instances in positions 1-3, not just "WAL" and so they would all need to return their associated value in column 2. Additionally, if the next set of characters in position 5-7 ("def" in the example you provided above) do not necessarily equal "FRT", then the default VLOOKUP of just the first 3 characters should execute and not generate "no match" because there will always be a match.

Basically, I'm trying to isolate the values which appear with FRT in the string and if false, default to the regular VLOOKUP that's already working. I hope this makes things clearer.

Thanks!
 
Upvote 0
=if(len($a2)-len(substitute($a2,"-",""))=1,vlookup(left($a2,3),handling,2,0),if(len($a2)-len(substitute($a2,"-",""))=2,vlookup(mid($a2,5,3),handling,2,0)))
 
Upvote 0
In B2 of Sheet1 enter and copy down:

=LOOKUP(9.99999999999999E+307,SEARCH("-"&Sheet2!$A$2:$A$3&"-","-"&$A2&"-"),Sheet2!$B$2:$B$3)

Name the range in column A of Sheet2 KEYS, the range in column B VALUES and invoke in B2 of Sheet2...

=LOOKUP(9.99999999999999E+307,SEARCH("-"&KEYS&"-","-"&$A2&"-"),VALUES)

if you like.
 
Upvote 0
=if(len($a2)-len(substitute($a2,"-",""))=1,vlookup(left($a2,3),handling,2,0),if(len($a2)-len(substitute($a2,"-",""))=2,vlookup(mid($a2,5,3),handling,2,0)))

Hey Jim, your solution works great!

I ran into a small problem I forgot to mention in the beginning. I found that the function errors when it encounters a subsequent dash "-" at the end of unique values. In order to make a string unique, an incrementing suffix is appended, like such:

WAL-123456 (BASE)
WAL-123456-001 (INCREMENTING SUFFIX)
WAL-123456-002 (INCREMENTING SUFFIX)
WAL-123456-003 (INCREMENTING SUFFIX)

The base and instances of FRT work awesome; however, when the function encounters any of the incrementing suffix values, it errors out. Knowing this, how can the function be modified to ignore the suffix portion?


Excel 2013 32 bit
AB
2WAL-395119214
3WAY-FRT-JAX118710
4WAL-37302139-111#N/A
AMZ FFIL
Cell Formulas
RangeFormula
B2=IF(LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))=1,VLOOKUP(LEFT($A2,3),HANDLING_TAB,2,0),IF(LEN($A2)-LEN(SUBSTITUTE($A2,"-",""))=2,VLOOKUP(MID($A2,5,3),HANDLING_TAB,2,0)))
Named Ranges
NameRefers ToCells
HANDLING_TAB=HANDLING!$A$2:$B$31
 
Upvote 0
In B2 of Sheet1 enter and copy down:

=LOOKUP(9.99999999999999E+307,SEARCH("-"&Sheet2!$A$2:$A$3&"-","-"&$A2&"-"),Sheet2!$B$2:$B$3)

Name the range in column A of Sheet2 KEYS, the range in column B VALUES and invoke in B2 of Sheet2...

=LOOKUP(9.99999999999999E+307,SEARCH("-"&KEYS&"-","-"&$A2&"-"),VALUES)

if you like.


Thanks Aladin. I'll try it out.
 
Upvote 0

Forum statistics

Threads
1,216,109
Messages
6,128,883
Members
449,477
Latest member
panjongshing

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