简体   繁体   English

vlookup:lookup_value作为日期范围

[英]vlookup: lookup_value as date range

Following Situation: 以下情况:

Sheet 1 provides a date range in two cells: 表格1在两个单元格中提供了日期范围:

Beginning____End

1.2013______2.2013

2.2013______3.2013...

Sheet 2 provides specific dates and values 表格2提供了特定的日期和值

3.1.2013_____500$

5.2.2013_____700$...

What I want to do now is insert the Values from Sheet 2 next to the right date ranges in Sheet 1. Please note that there is only one date (and thus one value) for each date range. 我现在想做的是将工作表2中的值插入工作表1中正确的日期范围旁边。请注意,每个日期范围只有一个日期(因此只有一个值)。

1.2013___ 2.2013___500$

2.2013___ 3.2013___700$

Usually in such a situation I would use Vlookup and match the dates, but that doesn't work since I would have to put a value range as lookup_value. 通常在这种情况下,我会使用Vlookup并匹配日期,但这不起作用,因为我必须将值范围设置为lookup_value。

I would be very thankful for your help. 感谢您的帮助。 This problem seems so easy but I can't seem to figure out a solution! 这个问题似乎很简单,但我似乎找不到解决方法! I tried to apply some solutions for similar problems I found here and on other websites but I haven't found a solution yet. 我试图为在这里和其他网站上发现的类似问题应用一些解决方案,但还没有找到解决方案。

Thanks and best regards! 谢谢,最好的问候!

I'm not sure whether there's an alternative, but this is what I came up with: 我不确定是否有其他选择,但这是我想出的:

=IF(VLOOKUP(C3,Sheet1!$B$3:$C$11,1)>=B3,VLOOKUP(C3,Sheet1!$B$3:$C$11,2),0)

First thing to note is that you had a 'floating' or unanchored range, which caused your LOOKUP() to work somewhat, but which would ultimately lead to a lot of wrong values. 首先要注意的是,您有一个“浮动”范围或未锚定范围,这导致您的LOOKUP()有所工作,但最终会导致很多错误的值。

To the formula, here's a little description: 对于公式,这里有一些描述:

VLOOKUP(C4,Sheet1!$B$3:$C$11,1)>=B4 this checks if the End of Period is equal to or before the date in Sheet1 we're looking for. VLOOKUP(C4,Sheet1!$B$3:$C$11,1)>=B4这将检查End of Period是否等于或Sheet1我们要查找的Sheet1的日期。 In case of month skipping, this bit is what takes care of it. 如果跳过一个月,则需要注意的一点是。

VLOOKUP(C3,Sheet1!$B$3:$C$11,2) this looks for the corresponding value of the date. VLOOKUP(C3,Sheet1!$B$3:$C$11,2)查找日期的相应值。

And I updated your file here . 在这里更新了您的文件。

As long as your dates on Sheet2 are in ascending order, you can still use VLOOKUP. 只要您在Sheet2上的日期按升序排列,您仍然可以使用VLOOKUP。 If you check the help for VLOOKUP you'll see that if the range_lookup parameter is omitted or TRUE, the function will match the first value that is equal to the search value, or the largest value that is less than the search value . 如果检查VLOOKUP的帮助,则会看到如果range_lookup参数省略或为TRUE,则该函数将匹配等于搜索值的第一个值, 或小于搜索值的最大值 So in your example, if cell B2 on Sheet1 contains 2.2013 then VLOOKUP(Sheet1!B2, Sheet2!$A$1:$B2) will return 500, because 3.1.2013 is the last value in the search column that's less than the search value (Excel treats a month.year date value as equal to 1.month.year). 因此,在您的示例中,如果Sheet1上的单元格B2包含2.2013VLOOKUP(Sheet1!B2, Sheet2!$A$1:$B2)将返回500,因为3.1.2013是搜索列中小于搜索值的最后一个值(Excel认为month.year日期值等于1.month.year)。

If there is always a value on Sheet2 for every month - ie it never skips from 5.2.2013 to 7.4.2013 for example - then VLOOKUP on its own should do what you need. 如果Sheet2上每个月有一个值(例如,它永远不会从5.2.2013跳到7.4.2013),那么VLOOKUP本身就可以满足您的需求。 If there are sometimes missing months on Sheet2 you'll need to limit the search range of the VLOOKUP function to prevent (in this example) the end date 4.2013 from returning the 5.2.2013 value. 如果在Sheet2上有时缺少月份,则需要限制VLOOKUP函数的搜索范围,以防止(在此示例中)结束日期4.2013返回5.2.2013值。 You can do this using the OFFSET and MATCH functions to construct a range for VLOOKUP's table_array that starts at the beginning of the date range you're looking for. 您可以使用OFFSET和MATCH函数为VLOOKUP的table_array构造一个范围,该范围从要查找的日期范围的开始处开始。 Use a match_type parameter of 1 in the MATCH function to make it behave in the same way as VLOOKUP. 在MATCH函数中使用match_type参数1,使其行为与VLOOKUP相同。

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

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