简体   繁体   中英

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

I have 2 columns (year and month). A sample data of year column A is 2015 at cell A2. A sample data of month column B is Jun at cell B2. I would like to convert these data to date format in column C to '2015-06-00` at cell C2. Is there a formula or Excel VBA to do this?

First off, 2015-06-00 is actually 31-May-2015. 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.

=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.

=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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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