简体   繁体   English

在Excel中获取当月右侧的单元格

[英]Get cell to the right of current month in Excel

I'm pretty new to Excel, that question is probably easy, but I dont know what to do :-(. So this is what I have: 我对Excel来说还很陌生,这个问题可能很简单,但是我不知道该怎么办:-(。这就是我所拥有的:

Date        Numbers
01.09.11      10   
01.10.11      20
01.11.11      30
01.12.11      40

Now what I want is in another cell: Get the number of the date, where the date's month is the current month. 现在我想要的是在另一个单元格中:获取日期的数字,其中日期的月份是当前月份。 How do I do this? 我该怎么做呢?

Assuming all your dates are strings of the form "dd.mm.yy", you can use the following array formula: 假设所有日期都是“ dd.mm.yy”形式的字符串 ,则可以使用以下数组公式:

=INDEX(B1:B4,MATCH(9,VALUE(MID(A1:A4,4,2)),0))

where the 9 is the month number you want to look up. 9是您要查找的月份号。 Enter this as an array formula by pressing Ctrl+Shift+Enter. 按Ctrl + Shift + Enter键将其输入为数组公式。

EDIT: 编辑:

As pointed out in the comments, you want to match the current month, so incorporating @JMax's suggestion works: 正如评论中指出的那样,您想匹配当前月份,因此合并@JMax的建议工作:

=INDEX(B1:B4,MATCH(MONTH(TODAY()),VALUE(MID(A1:A4,4,2)),0))

To clear up any confusion, MID() returns a string, which by itself will not return a match for the number value returned by MONTH(TODAY()) . 为了消除任何混淆, MID()返回一个字符串,该字符串本身不会返回与MONTH(TODAY())返回的数字值匹配的字符串。 However, if you stick the MID() function inside a VALUE() function, the string returned by MID() will be converted into a number value. 但是,如果将MID()函数放在VALUE()函数中,则MID()返回的字符串将转换为数字值。 Eg, "09" becomes the number 9, "10" becomes the number 10. This allows you to match the number value returned by MONTH(TODAY()) . 例如,“ 09”成为数字9,“ 10”成为数字10。这使您可以匹配MONTH(TODAY())返回的数字值。

However, if your dates are entered as dates with format dd.mm.yy in your sheet instead of as strings, then you can use the same strategy but with a different matching term: 但是,如果您在工作表中将日期输入为格式为dd.mm.yy的日期而不是字符串,那么您可以使用相同的策略,但使用不同的匹配项:

=INDEX(B1:B4,MATCH(MONTH(TODAY()),MONTH(A1:A4),0))

Enter this as an array formula. 输入它作为数组公式。

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

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