Finding # of years between 2 dates

Iceberg

Board Regular
Joined
Mar 12, 2008
Messages
79
Hello!

I am trying to write a bit of code to find the number of years between 2 columns of dates. I have one set of dates in Column D, another in E, and I would like the results to post in Column G.

Here's what I tried:

Rich (BB code):
For I = 2 To J
  Let Range("G" & I).Value = Range("E" & I).Value - Range("D" & I).Value
Next I

It works, but it gives me the number of days instead of the number of years.

Thanks in advance...!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Try this

Rich (BB code):
For I = 2 To J
  Let Range("G" & I).Value = Year(Range("E" & I).Value) - Year(Range("D" & I).Value)
Next I

Hope this helps.
 
Upvote 0

eblake

Active Member
Joined
Aug 18, 2004
Messages
258
Try this:

Code:
For I = 2 To J
    If Year(Range("E" & I).Value) > Year(Range("D" & I).Value) Then
        Range("G" & I).Value = Year(Range("E" & I).Value) - Year(Range("D" & I).Value)
    Else
        Range("G" & I).Value = Year(Range("D" & I).Value) - Year(Range("E" & I).Value)
    End If
Next I
 
Upvote 0

Forum statistics

Threads
1,191,196
Messages
5,985,227
Members
439,950
Latest member
Xearo96

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
Top