首页 > 解决方案 > 根据月份和年份查找单元格的值

问题描述

如果我不清楚你,我很抱歉。

我有例如:

Figure 1 :

| A        |       B  |
|01/05/2019|     500  |
|01/07/2020|  -100000 |
|01/12/2020|    7633  |

Figure 2 :

|     A    |   B       |
|01/05/2019|  -0.3521  |
|01/07/2020|    0.455  |
|01/12/2020|       0   |

我想在图 1 的 B 列的公式中包含与图 2 中的 A 列相关的月份和年份的值(在图 1 的 A 列中找到日期),记住天是不同的。

谢谢你。

标签: excelvbadatetimeexcel-formuladatetime-format

解决方案


我建议您使用帮助列,其中包含有关月份和年份的独特信息。问题是,你将如何做到这一点?我提出以下公式:

Helper(date) = 12*Year(date) + Month(date)

在哪里Year()Month()是用于检索日期的年数和月数的基本 Excel 函数。使用这种方法,您可以使用该VLookup()函数来查找您要查找的列,例如:

Figure1:
========

Helper |          A |       B  |
 24233 | 01/05/2019 |     500  |
 24247 | 01/07/2020 |  -100000 |
 24252 | 01/12/2020 |    7633  |

Figure2: (with some modification, I used the second day of the month to clarify 
========  the correctness of the provided formula)

Helper |          A |       B  |
 24233 | 02/05/2019 |  -0.3521 |
 24247 | 02/07/2020 |    0.455 |
 24252 | 02/12/2020 |       0  |

如您所见,一个简单的VLookup()可用于搜索值 24233、24247、24252、...


推荐阅读