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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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
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,214,636
Messages
6,120,669
Members
448,977
Latest member
moonlight6

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