简体   繁体   English

在使用 Web 外部数据时使用 vlookup

[英]Using vlookup while using web external data

Good afternoon,下午好,

I am pulling a fuel database from gasbuddy and trying to use the VLOOKUP function to grab address, prices and times last updated.我正在从 gasbuddy 提取燃料数据库并尝试使用VLOOKUP功能来获取地址、价格和上次更新时间。 However, all I am getting are #N/A (value not available) results.但是,我得到的只是#N/A(值不可用)结果。 My code is below:我的代码如下:

=VLOOKUP(
  N5,
  GasPriceSearch.aspx?typ_adv_fuel_limit_36,
  COLUMN(B5),
  FALSE)

I tried converting this information into a table and the formula works but I run into issues where new fuel prices are reported and it messes up the entire table.我尝试将此信息转换为表格并且公式有效,但我遇到了报告新燃料价格的问题并且它弄乱了整个表格。 I would rather do it from the initial data without a table.我宁愿从没有表格的初始数据开始。

在此处输入图像描述

Thank you, Jesse谢谢你,杰西

There are several ways to achieve this.有几种方法可以实现这一点。 However, based on your data structure, a regular VLOOKUP won't work because VLOOKUP only searches to the right of the lookup value (ie, the address) and, for example, the price is to the left of it.但是,根据您的数据结构,常规VLOOKUP将不起作用,因为VLOOKUP仅搜索查找值(即地址)的右侧,例如,价格在其左侧。 Thus, one possibility would be to restructure your data so that you have address, price, update, and so on.因此,一种可能性是重组您的数据,以便您获得地址、价格、更新等信息。 This would also circumvent the problem of having the price on a different row than the lookup value.这也将避免价格与查找值位于不同行的问题。

Another way to work with this data structure is to use the INDEX function:使用此数据结构的另一种方法是使用INDEX函数:

=INDEX(array, row_num, [column_num])

Your array reflects the range where your data is stored that you want to look up;您的数组反映了您要查找的数据存储范围; in your case, considering only price and station A:B .在您的情况下,仅考虑价格和站A:B Since you've hidden some columns, it's hard to see what else is in this datasheet.由于您隐藏了一些列,因此很难查看此数据表中的其他内容。 But just adjust it to your needs of the data.但只需根据您对数据的需求进行调整。

The row number can be hard coded.行号可以硬编码。 However, since you want to look up a specific value (ie, address), you can use the MATCH function:但是,由于您要查找特定值(即地址),您可以使用MATCH函数:

=MATCH(lookup_value, lookup_array, [match_type])

In this step you want to look up your address from column N in column B, where all stations are listed.在此步骤中,您要从 B 列的 N 列中查找您的地址,其中列出了所有车站。 You also need to specify the column you want to return.您还需要指定要返回的列。 Again, you can either hard code it or use the MATCH function.同样,您可以对其进行硬编码或使用MATCH函数。 With the match_type you can specify, for example, that you only want an exact match, ie, match_type = 0 .例如,您可以使用match_type指定您只需要完全匹配,即match_type = 0

To return the value "update" to the left of the address, your formula looks as follows:要将值“更新”返回到地址的左侧,您的公式如下所示:

=INDEX($A:$B,MATCH(N6,$B:$B,0),1)

To return the address itself (which is pretty much useless, since you already have it in column N), use the following formula with the adjusted column value from 1 to 2:要返回地址本身(这几乎没有用,因为您已经在 N 列中拥有它),请使用以下公式,将列值从 1 调整为 2:

=INDEX($A:$B,MATCH(N6,$B:$B,0),2)

Lastly, your price information is one row above the address, you need to adjust the number of rows by -1 accordingly.最后,您的价格信息在地址上方一行,您需要相应地调整行数 -1。 That is, if your address is, for example, 4123 Town [...], you want to return column 1 of row 6 and not row 7:也就是说,例如,如果您的地址是 4123 Town [...],您希望返回第 6 行的第 1 列而不是第 7 行:

=INDEX($A:$B,MATCH(N6,$B:$B,0)-1,1)

An alternative strategy would be to use the XLOOKUP function (only available in newer versions of Excel), which allows you to find values to the left of the lookup value.另一种策略是使用XLOOKUP函数(仅在较新版本的 Excel 中可用),它允许您查找查找值左侧的值。 But also with this strategy you would have to deal with the problem of row differences.但同样使用这种策略,您将不得不处理行差异问题。 The OFFSET function could prove useful in this context, but it does not make the approach much easier than the INDEX function.在这种情况下, OFFSET函数可能很有用,但它并不比INDEX函数更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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