Merging year and date column into one date column

Koala20171990

New Member
Joined
Oct 20, 2017
Messages
6
Hi all,

Another quick question: I currently have a spreadsheet that has a year column and an effective date column which has the month and day. I'm looking for a macro that will merge the two columns into one with the format (month-day-year). Any advice is greatly appreciated!
Right now, the format looks like this:
YearEffective
Date
200019-May
1-Jul
200119-May
Thanks!1-Jul





<tbody>
</tbody><colgroup><col><col></colgroup>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Where is this located, what columns? is the effective date text or an Excel date? Where do you wan the merged date?
 
Last edited:
Upvote 0
The columns are located within a table, the year column is in column B and the effective date is in column C, I want the combined date to be in a new column (column D). The date is an Excel date in the format d-mmm.
 
Upvote 0
200119 Jul=MONTH(B1)=DAY(B1)=DATE(A1,C1,D1)

<tbody>
</tbody><colgroup><col><col><col><col><col><col></colgroup>


dont know if this will help
 
Upvote 0
This would work if there's a matching year entry for every effective date entry. The problem is that multiple effective dates are categorized under the same year so there are blanks in the year column when the year remains consistent but the effective date is changed.

For example
200019-May
1-Jul
200119-May
1-Jul

<tbody>
</tbody><colgroup><col><col></colgroup>
There are two effective dates for the year 2000 and 2001, so there's a blank in the second and fourth rows. Using the date function in those rows would not yield the correct date.
 
Upvote 0
You should fill in those blanks, so that every record has a Year specified. (this will help in the long run, not just for this task)
If it's a matter of having so many records that it would be too much work, it's really not.
You can do them all at once.

You can highlight that column with the years
Press CTRL+G
Click Special
Select Blanks
Click OK
Press =
Press UP Arrow
Pess CTRL + ENTER
 
Last edited:
Upvote 0
And here's another method as well..

=EDATE(B1,-(YEAR(B1)-A1)*12)

A1 = Year
B1 = Effective DAte
 
Upvote 0
I agree with Jonmo1 you are better off with the year in every record.

This should work if you do not add the year to every record.
Code:
Sub mergedate()
Dim lr As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row

For x = 2 To lr
    If Range("B" & x) = "" Then
    Else
        myyear = Range("B" & x)
    End If
    
    mymonth = Month(Range("C" & x))
    myday = Day(Range("C" & x))
    Range("D" & x) = DateValue(mymonth & "/" & myday & "/" & myyear)
Next x

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,637
Messages
6,125,965
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top