简体   繁体   中英

Excel 2003: Match value in column A with column B, then pull data from column B

I am attempting to write a formula in Excel 2003.

Situation:

Column A corresponds to column B. Column C corresponds to column D. There are multiple rows in column A that match a single row in column C.

       Column A   Column B          Column C     Column D
  1    1247       ≥ 98.5%        1247         ≥ 98.5%
  2    1250       ≥ 99.9%        1250         ≥ 99.9%
  3    1258       ≥ 99.9%        1258         ≥ 99.9%
  4    1341       ≥ 99%          1341         ≥ 98%
  5    1341       ≥ 99%          1349         ≥ 99%
  6    1349       ≥ 60%          1376         ≥ 99%
  7    1349       ≥ 60%          1644         ≥ 60%

Problem

I need the values from Column D to replace the values in column B.

Attempt

  1. Select a value in column A
  2. Match this value in column C
  3. Based on value in column C, copy data from D.
  4. Paste data into Column B.

      =IF(ISERROR(MATCH(A1,$C$1:$C$,)),ERROR,VLOOKUP(A1,$C$1:$D$7,2)) 

When I use this code the incorrect values from column D are pulled. B4 and B5 should have pulled value from D4 only. B6 and B7 from D5 only.

Any suggestions?

There are three issues in your formula:

  1. The first lookup range is incomplete $C$1:$C$ and should be $C$1:$C$7 .
  2. You're not using the match type and the extra comma will leave an error.
  3. You didn't specify whether the lookup is an exact match or approximate match. By default, VLOOKUP uses approximate matching, which is why you are getting wrong results.

The following should work as you intended it to:

=IF(ISERROR(MATCH(A1,$C$1:$C$7,0)),ERROR,VLOOKUP(A1,$C$1:$D$7,2,0))

However, you can shorten the formula with IFERROR :

=IFERROR(VLOOKUP(A1, $C:$D, 2, 0), "Error")

If you have to look through a large number of values, it would take a lot of time anyway, so that's why I removed the row limits. The IFERROR will try to evaluate the VLOOKUP first and if it returns #N/A , the IFERROR will return "Error" instead. Otherwise, it will return the value you're looking for from the VLOOKUP .

It should also speed things up a bit, since Excel doesn't have to first check for the MATCH and then evaluate the VLOOKUP .

I tested your formula, and it works. I only replaced $C$1:$C$, by $C$1:$C$7, (does this look ok to you?)

在此处输入图片说明

I guess you used the right formula in your worksheet, and this is a typo only here, since an error pops when trying to enter the wrong formula.

If this assumption is correct, and the error is somewhere else, can you specify what incorrect values from column D are pulled?

It does not look like this is causing issues in your example, but you might want to specify that exact matches are required on the lookups. You do this by adding a ",0" to the MATCH and VLOOKUP formulas. Like this:

=IF(ISERROR(MATCH(A1,$C$1:$C$7,0)),"ERROR",VLOOKUP(A1,$C$1:$D$7,2,0))

EDIT: Also, I think "ERROR" should be in quotes, since it seems you want the formula to print this out as a message. (Note that without the exact match requirement, the original formula would not return this ERROR, it would find the next closest result.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM