简体   繁体   English

Excel公式或VBA将年,月数据转换为实际日期

[英]Excel Formula or VBA to convert year, month data to actual date

I have 2 columns (year and month). 我有2列(年和月)。 A sample data of year column A is 2015 at cell A2. 单元格A2的年份列A的样本数据为2015 A sample data of month column B is Jun at cell B2. 月列B的样本数据在单元格B2中为Jun I would like to convert these data to date format in column C to '2015-06-00` at cell C2. 我想将这些数据转换为单元格C2中C列中的日期格式为'2015-06-00'。 Is there a formula or Excel VBA to do this? 是否有公式或Excel VBA可以做到这一点?

First off, 2015-06-00 is actually 31-May-2015. 首先,2015-06-00实际上是2015年5月31日。 If you supply zero as the day-of-the-month, you get the last day of the previous month. 如果您提供零作为当月的一天,则得到上个月的最后一天。 Typically you would set it for the first day of the month. 通常,您将其设置为该月的第一天。 Use the DATE function for this with 1 as the day_num parameter or the DATEVALUE function if you are stringing together text-that-looks-like-a-date. 为此,请使用DATE函数 (将1作为day_num参数)或DATEVALUE函数(如果您将看起来像日期的文本串在一起)。

=datevalue(B2 & " 1, " & A2)

With a three letter month in B2, you will have to translate that to a numerical month if you opt for the DATE function. 如果在B2中使用三个字母的月份,那么如果选择DATE函数,则必须将其转换为数字月份。

=DATE(A2, LOOKUP(B2, {"Apr","Aug","Dec","Feb","Jan","Jul","Jun","Mar","May","Nov","Oct","Sep"}, {4,8,12,2,1,7,6,3,5,11,10,9}), 1)

在单元格C中“ = FECHA(A2; B2; 1)”(西班牙语excell)

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

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