简体   繁体   English

在Excel中找到正确的vlookup / index公式以匹配星期和日期

[英]Finding the right vlookup/index formula in excel to match weeks and dates

I have two sheets on excel. 我有两张关于excel的表。 Sheet1 consists of data from other sheets so Sheet1 is the main Sheet to look at. Sheet1由其他工作表中的数据组成,因此Sheet1是要查看的主要工作表。 I am having trouble finding a vlookup formula that can get the accurate information from Sheet2. 我很难找到可以从Sheet2获取准确信息的vlookup公式。 On Sheet1, in column AI have item numbers and in row 1 I have dates that alternate weekly (16-Jul, 23-Jul, 30-Jul, 6-Aug, etc.). 在Sheet1的AI列中,有商品编号,在第1行中,我具有每周交替的日期(7月16日,7月23日,7月30日,8月6日等)。 On Sheet1, for each weekly date and item number I get a numerical amount from Sheet2. 在Sheet1上,对于每个每周的日期和项目编号,我从Sheet2获得一个数值。 Sheet2 has the same exact layout except instead of dates in row 1, there are week numbers ([starting from the example dates above] 29, 30, 31, 32, etc.). Sheet2具有相同的确切布局,除了第1行中的日期以外,还有周数([从上面的示例日期开始] 29、30、31、32等)。 The week numbers change daily on Sheet2 so for example today it can be 29,34,45,46,51. 在工作表Sheet2上,星期几每天都会更改,因此例如,今天可以是29,34,45,46,51。 Right now I have a large range to account for multiple possible future item numbers and weekly numbers andthe best I have is: 现在,我有很大的范围来考虑多个可能的将来商品编号和每周编号,而我的最佳选择是:

=IF(ISNA(VLOOKUP(LEFT($A2,LEN($A2)),'Sheet2'!$A$2:$AZ$8000,COLUMN()-4,0)),"",VLOOKUP(LEFT(Summary!$A2,LEN(Summary!$A2)),'Sheet2'!$A$2:$AZ$8000,COLUMN()-4,0)) = IF(ISNA(VLOOKUP(LEFT($ A2,LEN($ A2)),'Sheet2'!$ A $ 2:$ AZ $ 8000,COLUMN()-4,0)),“” ,, VLOOKUP(LEFT(Summary! $ A2,LEN(摘要!$ A2)),'Sheet2'!$ A $ 2:$ AZ $ 8000,COLUMN()-4,0))

but the problem lies with the "COLUMN()-4" as I do not know what this does nor does it capture the correct date because it gets the amount but it assumes that all possible dates on Sheet1 (16-Jul, 23-Jul, 30-Jul, 6-Aug, etc.) have no gaps when on Sheet2 there are because not all week numbers are listed. 但是问题出在“ COLUMN()-4”上,因为我不知道该怎么做,也不捕获正确的日期,因为它获取了金额,但它假定Sheet1上的所有可能日期(7月16日,7月23日,7月30日,8月6日等)在Sheet2上没有空格,因为没有列出所有星期数。 I cannot list them all on Sheet2, only whatever week number and item number is updated and appears, so there are gaps (whereas Sheet1 has every date and whatever does not appear is just left as a blank cell since it is not relevant). 我无法在Sheet2上全部列出它们,仅更新和显示星期几和项目号,所以存在空白(而Sheet1包含每个日期,而没有出现的东西则作为空白单元格保留,因为它不相关)。 Finding a way to change the formula to match the week number with the date might be a possible solution? 寻找一种方法来更改公式以使星期数与日期匹配可能是一种可行的解决方案? Hope this makes sense! 希望这有道理! The workbook is saved daily with a new date. 该工作簿每天都会保存一个新日期。

google sheet link 谷歌表链接

Sheet1 工作表1

Sheet2 工作表2

Why don't try to use : 为什么不尝试使用:

  1. Use weeknum() for week number of the year. 使用weeknum()作为一年中的第几周。 instead of manually setting it. 而不是手动设置。 eg Let A1 = the date, =WEEKNUM(A1) 例如,假设A1 =日期, =WEEKNUM(A1)

  2. For checking of empty cell , use iferror() or if() to check/zero-fill to check for blank cell. 要检查空单元格,请使用iferror()或if()进行检查/零填充以检查空白单元格。 eg. 例如。 =IF(A1="",WEEKNUM(A1),"")

  3. Use index-match instead of vlookup. 使用索引匹配而不是vlookup。 It may be used to look for match both vertically and horizontally.. ref -> http://www.mbaexcel.com/excel/how-to-use-index-match-match/ 它可用于查找垂直和水平方向的匹配。ref-> http://www.mbaexcel.com/excel/how-to-use-index-match-match/
    eg > Let A2 = a, B2 = b, C2 = c, A3 = 30, B3 = 40, C3 = 50 . 例如>令A2 = a,B2 = b,C2 = c,A3 = 30,B3 = 40,C3 = 50。 using A5 as text(a/b/c) input, =INDEX(A3:C3,1,MATCH(A5,A2:C2,0)) 使用A5作为文本(a / b / c)输入=INDEX(A3:C3,1,MATCH(A5,A2:C2,0))

eg2 > Let A10 = a, A11 = b, A12 = c, B10 = 30, B11 = 40, B12 = 50 , =INDEX(B10:B12,MATCH(A5,A10:A12,0)) eg2>设A10 = a,A11 = b,A12 = c,B10 = 30,B11 = 40,B12 = 50, =INDEX(B10:B12,MATCH(A5,A10:A12,0))

Hope that helps. 希望能有所帮助。 (: (:

+-------[ Edit ]---------+ + ------- [编辑] --------- +

Thanks for the shared files & screenshoot. 感谢您的共享文件和屏幕截图。 Congratulations on finding the solution =IFERROR(INDEX(Sheet2!$B$2:$AZ$8000,MATCH($A3,Sheet2!$A$2:$A$8000,0),MATCH(WEEKNUM(B$1),Sheet2!$B$1:$AZ$1,0)),"") on your own. 恭喜找到解决方案=IFERROR(INDEX(Sheet2!$B$2:$AZ$8000,MATCH($A3,Sheet2!$A$2:$A$8000,0),MATCH(WEEKNUM(B$1),Sheet2!$B$1:$AZ$1,0)),"")靠自己。 It is indeed a very good solution. 这确实是一个很好的解决方案。 Keep it up. 保持。 (: (:

Try this in Summary!B2 then fill both right and down. 在Summary!B2中尝试此操作,然后向右和向下填充。

'excel formula
=iferror(hlookup(weeknum(B$1, 2), Sheet2!$B$1:$AZ999, match($A2, Sheet1!$A:$A, 0), false), "")
'google-sheets formula
=iferror(hlookup(weeknum(B$1, 2), Sheet2!$B$1:$AZ, match($A2, Sheet1!$A:$A, 0), false), "")

The accuracy of the HLOOKUP will depend on whether your WEEKNUM's match the Excel default for WEEKNUM. HLOOKUP的准确性将取决于您的WEEKNUM是否与Excel默认的WEEKNUM相匹配。 I noticed your dates are the Monday starting the week so I've use WEEKNUM(<date>, 2). 我注意到您的日期是从一周的星期一开始,因此我使用了WEEKNUM(<date>,2)。 If your weeknum's are offset from excel defaults (implied by the COLUMN()-4 parameter) then this will have to be adjusted. 如果您的周数偏离了excel默认值(由COLUMN()-4参数表示),则必须对此进行调整。

Shared worksheet 共享工作表

在此处输入图片说明

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

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