Hello,

Suppose you have a spreadsheet which contains a 3-column table.

**What formula would enable a user to enter a value from either the 1st **__or__ 2nd column but always return the values found in the 2nd __and__ 3rd columns of the corresponding row?

For example, the table in the following screenshots contains three ways (*written* in columns 1 & 2 and *numeric* in column 3) to designate months. Also included is an input box (yellow) in which a user can enter a given month — but only in one of the written forms from the 1st (Fig. 1) or 2nd (Fig. 2) columns of the table (ie numeric entries are not allowed):

**What formula would return the result shown in the blue box regardless of which of the two written forms was utilized by the user?**

*Notes:*

*1) the use of months in this example is arbitrary (ie please avoid solutions which include date or time functions).*

*2) Please disregard the fact that each of the 2nd-column values in the table not only contains exactly three letters but the first three letters of the corresponding 1st-column values. That is just a coincidence of this example but does not apply where I plan to use the solution.*

The best approach I've found so far involves naming two defined ranges:

• "Months3" which includes all three columns (Fig. 3) and

• "Months2" which includes the 2nd & 3rd columns but not the 1st column (Fig. 4):

With the named ranges and utilizing the =VLOOKUP() function, two separate formulas can be written, one for inputs from the 1st column (Fig. 5):

and one for inputs from the 2nd column (Fig. 6):

*Note: the function =GET.CELL(6,F8) enables the display (red font) of the adjacent formulas in F8 & F9.*

I believe this approach is usable but as can be seen in Fig. 6, each formula works for entries from one of the first two columns*but returns #N/A for the other*. Therefore, if someone can **show me how to nest the two =VLOOKUP() formulas into one** so that the 1st column is searched first and the 2nd column is searched only if the 1st column search fails, I think that will do it.

**Alternatively, I am interested in learning different but simpler ways to arrive at the same endpoint.**

Thanks

Suppose you have a spreadsheet which contains a 3-column table.

For example, the table in the following screenshots contains three ways (

The best approach I've found so far involves naming two defined ranges:

• "Months3" which includes all three columns (Fig. 3) and

• "Months2" which includes the 2nd & 3rd columns but not the 1st column (Fig. 4):

With the named ranges and utilizing the =VLOOKUP() function, two separate formulas can be written, one for inputs from the 1st column (Fig. 5):

and one for inputs from the 2nd column (Fig. 6):

I believe this approach is usable but as can be seen in Fig. 6, each formula works for entries from one of the first two columns

Thanks

```
If(iserr(vlookup(f3,$range,3,False)),vlookup(f3,$range2,2,False),vlookup(f3,$range,3,False)
```

Basically, check to see if looking up f3 in column 1 of $range (3 columns) returns a value - if so, ISERR returns false, and the 2d formula (which is the same as the test formula) is used to get a result from the 3rd column. If the test lookup fails and returns an error (might return null, I'll do some research), then use the 2d formula, which looks up the value in column 1 of the 2-column range and returns the value in column 2 thereof.

```
=IFNA(VLOOKUP(F1,range3col,3,FALSE),VLOOKUP(F1,range2col,2,FALSE))
```

It's basically the same logic, but there's 2 changes:1) If the lookup fails, it return #N/A, which is NOT an error value;

2)There's an IFNA function (not sure when that was added) that makes the code easier to read

In the formula above, F1 is the input cell and range3col and range2col refer to named ranges

By the way, the FALSE argument just tell VLOOKUP not to try to an interpolated match - if it's looking for "b" in the list "a","c","e" it will return "a" if the 4th argument is null or True.

=LEFT(F3,3)&" is month #"&INDEX(D2:D13,MATCH(F3,I

This one is on us!

(Get your first solution completely free - no credit card required)

UNLOCK SOLUTION
Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.