Do vampires prefer a specific blood type? Type A? Type B? Type AB? Are you positive? During the holidays, they might drink glögg, or Cosmopolitans!
Anyway, Marsha probably isn't a vampire, but she wants to choose A or AB when doing a VLOOKUP. Here's how you can combine values for Excel VLOOKUP formulas.
Here's what Marsha needs to do:
- If there is only a value in column A, use A for the VLOOKUP
- If there is also a value in column B, use A & B for the VLOOKUP
The Data Layout
I don't have a copy of Marsha's Excel file, but her lookup table, with Parts information, might look something like the screen shot below.
In column A, there's a 3 letter code for each part, and some codes have a number at the end, to indicate length.
The lookup table is named PriceLU, as you can see in the Name Box, at the top left of the screen shot.
Enter an Order
When customers enter an order, they put in a part code, and sometimes they enter a part length.
In columns C and D, a VLOOKUP formula can pull the description and price from the PriceLU table.
Single VLOOKUP Value
For a normal VLOOKUP formula, you'd refer to a single cell as the lookup value.
For example, the following formula would get the price for a wrench (WRN) from the price lookup table:
Combine the VLOOKUP Values
However, if there is a length in column B on the Orders sheet, you need to include that as part of the lookup value.
In the first argument of the VLOOKUP formula, you can check for a value in column B. If there's something in that cell, show a hyphen and the value in column B.
IF($B2,"-","") & $B2
Here's the revised VLOOKUP formula, that combines the values in columns A and B, when necessary, to get the price, from column 3 in the lookup table:
=VLOOKUP($A2 & IF($B2,"-","") & $B2,PriceLU,3,FALSE)
The same VLOOKUP formula is used in column C, with the lookup column changed to 2, to get the Part description from the lookup table.
=VLOOKUP($A2 & IF($B2,"-","") & $B2,PriceLU, 2, FALSE)