trying to expand vlookup to other cells without automatically changing values

流过昼夜 提交于 2019-12-13 05:05:24

问题


I am setting up a vlookup to pull product prices from another sheet within the workbook. The code works for the cell but when i try to expand or copy and past the code into the next row it automatically changes the data table_array value.

=VLOOKUP(B5,Prices!1:65536,3)

Within the code i want the first value, B5 to scale with the row it is in, however the second value needs to remain the same. How do i go about doing this? Also is there a way that i can get the cell to remain blank instead of displaying N/A if there isnt a valid part number?

Thanks for your help!


回答1:


For the second part, an IF formula will work fine:

=IF(ISERROR(VLOOKUP(B5,Prices!1:65536,3)),"",VLOOKUP(B5,Prices!1:65536,3)),"")

And if I understand correctly the first part have you tried set an absolute value? Something like:

    =IF(ISERROR(VLOOKUP(B$5,Prices!1:65536,3)),"",VLOOKUP(B5,Prices!1:65536,3)),"")



回答2:


=VLOOKUP(B5,Prices!$1:$65536,3)

The $ lock the range.

For example.

  • $A1 will lock the column to A when the formulas is copied other locations.
  • A$1 will lock the row
  • $A$1 will lock both the column and the row.



回答3:


I can't comment because I do not have enough rep but this will fix user3716271 's formula:

=IF(ISERROR(VLOOKUP(B5,Prices!$1:$65536,3)),"", VLOOKUP(B5,Prices!$1:$65536,3))

The following formula should solve both problems as well, a little more compact and would use one less VLOOKUP():

=IFERROR(VLOOKUP(B5,Prices!$1:$65536,3), "")

As guitarthrower had said, the $ before the number is used to lock the range.



来源:https://stackoverflow.com/questions/24831919/trying-to-expand-vlookup-to-other-cells-without-automatically-changing-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!